NullPointerException At Statement stmt = conn.createStatement();
JiaPei Jen
Ranch Hand
Joined: Nov 19, 2000
Posts: 1309
posted
0
I am trying to use a connection pool to retrieve data from a database. I have succeeded in putting InitialContext, DataSource, Statement, ResultSet in "one servlet". And I am able to display the output in the browser. It means that the table is created in the database, the connection pool is properly configured, DataSource is referenced in the web.xml, and mapping in the web.xml has been taken care of. I ran into problem when I tried to put IntialContext and DataSource in one class (DBConnection.java) that specializes in providing Connection object (conn). And another class (VerificationServlet.java) with Statement and ResultSet in it references the provided Connection object. (DBConnection.java and VerificationServlet.java are in a package 'cptest'.) The error message I got is "java.lang.NullPointerException at cptest.VerificationServlet.doGet(VerificationServlet.java:25) and the 25th line of the VerificationServlet is Statement stmt = conn.createStatement(); I am lost. I do not know what went wrong. DBConnection.java VerificationServlet.java
If an exception is thrown, you hide the exception and return null. Are you sure there is no exception being thrown? This would cause a NullPointer every time.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: NullPointerException At Statement stmt = conn.createStatement();