why this simple method does't work?

hi guys, could you tell me why this servlet does't work?

import java.io.*;

import java.sql.*;

import java.net.*;

import java.util.*;

import java.text.*;

import javax.servlet.ServletException;

import javax.servlet.http.*;

import javax.servlet.*;

import javax.sql.*;

publicclass sqlextends HttpServlet{

static Connection getSimpleConnection(){

Connection result =null;

try{Class.forName("com.mysql.jdbc.Driver").newInstance();}

catch (Exception ex){System.err.println("Check classpath. Cannot load db driver: ");}

try{result = DriverManager.getConnection("jdbc:mysql://localhost:3306/zuak","user","pasw");}

catch (SQLException e){System.err.println("Driver loaded, but cannot connect to db: ");}

return result;

}

publicvoid doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException

{

response.setContentType("text/html;charset=utf-8");

PrintWriter out = response.getWriter();

String st ="36";

String query ="SELECT * FROM data where id=?";

try{

Connection con = getSimpleConnection();

PreparedStatement ps = con.prepareStatement(query);

ps.setString(1, st);

ResultSet rs = ps.executeQuery();

while (rs.next()){

String type = rs.getString("type");

String parent_id = rs.getString("parent_id");

String name = rs.getString("name");

String idd =rs.getString("id");

out.println(type+", "+name+" ,"+idd+". ");

}

}

catch (Exception e){out.println(e);}

}

}

thanks a lot

[3434 byte] By [newj87a] at [2007-11-27 5:04:46]
# 1
What does "doesn't work" mean?
CeciNEstPasUnProgrammeura at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...
# 2
no connection, java.lang.NullPointerException i would like to use getSimpleConnection(), it seems that this method doesn't work, it's possible to use in in corect way? thanks
newj87a at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...
# 3

> no connection,

> ava.lang.NullPointerException

Stack trace? Where does it occur?

> i would like to use getSimpleConnection(),

What is that?

> it seems

> that this method doesn't work,

"doesn't work" again. Listen, we're not mind readers here. You're supposed to provide as much information about your problem as possible.

CeciNEstPasUnProgrammeura at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...
# 4
By the way, no more help of mine until not every single one of your catch blocks prints the exception's stack trace.
CeciNEstPasUnProgrammeura at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...
# 5
my mistake sorry guys
newj87a at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...
# 6
thanks CeciNEstPasUnProgrammeur for your help my mistake, sorry
newj87a at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...
# 7

I think your NullPointerException is caught and printed in you last catch block:

catch (Exception e) {out.println(e);}

change it to print the stack trace, and post the stack trace.

(If you don't know how to print the stack trace check the javadoc on the Throwable interface: http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Throwable.html)

tom_jansena at 2007-7-12 10:23:10 > top of Java-index,Java Essentials,Java Programming...