14 messages in com.mysql.lists.javaconnecting problem from servlet to my...
FromSent OnAttachments
Sa Lin07 Jun 2000 22:50 
Cris Perdue08 Jun 2000 08:22 
Sa Lin08 Jun 2000 13:01 
Dave Harms08 Jun 2000 13:12 
Bill Hause08 Jun 2000 13:20 
Tim Endres08 Jun 2000 13:38 
Barry Cornelius08 Jun 2000 15:20 
Tim Endres08 Jun 2000 18:48 
Sa Lin08 Jun 2000 19:57 
Asif Raj08 Jun 2000 23:25 
Bill Hause09 Jun 2000 06:20 
Sa Lin09 Jun 2000 15:15 
Mark Matthews09 Jun 2000 19:44 
Asif Raj10 Jun 2000 03:21 
Subject:connecting problem from servlet to mysql
From:Sa Lin (sl@cs.iastate.edu)
Date:06/09/2000 03:15:07 PM
List:com.mysql.lists.java

Hi,

My problem still exists. This String declaration without new seems ok with my system. I changed to your way, but still the same results.

One thing I want to get help is if someone could decribe those tables in mysql database. What are the least setups needed in order to get connected to database thru JDBC (I use mm.mysql-2.0.1-bin.jar). I granted full permission to the user I used in DriverManager.getConnection(), but my host table is empty. Do I need to set up sth. in host table? Or do I need to set up anything for other tables? One thing I want to mention again is I can retrive or insert data by using jdbc without servlet, but I could not get connected from my servlet. Could someone help me? It's urgent. Thank you in advance.

Sa

On Fri, 9 Jun 2000, Asif Raj wrote:

Hey, did u check the block where u r building the query, I think u need to initialise the query. cos i tried the same way to initialise the query string it did not work. try this

String query = new String("whatever");

please let me know the results

asif

On Thu, 8 Jun 2000, Sa Lin wrote:

Thank you very much for your reply. I commended the JDBC part and it works. I modifed some of my codes according to the suggestions I got, but I still got some errors. Here I attched the complete codes. Hope someone could help me out.

import javax.servlet.*; import javax.servlet.http.*;

import java.io.*; import java.sql.*;

public class adduser1 extends HttpServlet {

Connection dbCon; Statement stmt; String qry = null;

public void init(ServletConfig conf) throws ServletException {

// Connect to the database try{ Class.forName("org.gjt.mm.mysql.Driver").newInstance(); Connection dbCon = DriverManager.getConnection( "jdbc:mysql://chatcher.iastate.edu:3306/test?user=s&password=s"); } catch (java.lang.Exception E) { System.out.println("** Error on data selected. **"); E.printStackTrace(); } }

public void doPost(HttpServletRequest _req, HttpServletResponse _res) throws ServletException, IOException {

_res.setContentType("text/html"); PrintWriter out = _res.getWriter();

// Get eq.getParameter("password1"); String _street = _req.getParameter("street"); String _city = _req.getParameter("city"); String _state = _req.getParameter("state"); String _zip = _req.getParameter("zip"); String _phone = _req.getParameter("phone");

// Build Query String qry = "insert into users (usr_email, usr_lname, usr_fname," + "usr_pwd) values('" + _email + "', '" + _lname + "' "+ ", '"+ _fname + "' ,'" + _pwd + "')";

// Execute Query try{ stmt = dbCon.createStatement(); stmt.executeUpdate(qry); stmt.close(); dbCon.close(); } catch(SQLException e) { _res.sendError(_res.SC_ACCEPTED, "The request has been accepted, but it failed to complete due to a problem querying the database."); return; }

/* Output Results */ out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>adduser</TITLE>"); out.println("<BODY>"); out.println("Welcome '"+_fname +"' ! Now you are a new user!"); out.println("</BODY>"); out.println("</HTML>");

out.close(); } }

in my register.htm file I used <form method="Post" action="http://chatcher.fcs.iastate.edu:8080/servlets/adduser1" ...

I got following error when I submitted the form: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.

Then I checked my log file, I got: [08/06/2000 14:22:27:776] (ERROR) ajp12: Servlet Error: java.lang.NullPointerExterException: null [08/06/2000 14:22:27:776] (ERROR) an error returned handling request via protocrotocol "ajpv12"

Again, without servlet, I used a java file testing the JDBC connection, it works fine. The only difference in that code I use Connection dbCon = DriverManager.getConnection("jdbc:mysql://localhost/test?user=s&password=s"); Here I specify the server name plus port number. I tested both cases for my servlet adduser1.java, both failed. I think I got some configuration problems, but couldn't figure it out. Could you give me some idea? Thanks!

Sa

On Thu, 8 Jun 2000, Cris Perdue wrote:

This does not look like a JDBC problem, but rather a problem between your browser and web server, judging from the error message.

You might want to comment out the JDBC code in your servlet, changing the logic so it "does nothing" related to the database, but returns a page to the browser. Then see what happens when you recompile and run that servlet.

-Cris

To unsubscribe, send a message to the address shown in the List-Unsubscribe header of this message. If you cannot see it, e-mail java@lists.mysql.com instead.