Alison Lindores wrote:
> Hi,
>
> I have not been using servlets for very long. I have a book on servlet
> programming and in that book is a simple database application. I am
> currently working on something similar so I copied the code in the book and
> tried to run it. The code compiles fine (i'm using JSDK2.0 and JDK2) but
> when I start the servletrunner and open the web page that calls the servlet
> code, the following error is brought up in the servletrunner window -
> SimpleServlet: init
> java.lang.NullPointerException:
> at SimpleServlet.doGet(SimpleServlet.java:75)
[snip]
This line of the exception traceback indicates that the error occurs at line 75
of SimpleServlet. In other words, it is the line that says:
stmt = dbCon.createStatement();
and the easiest way this statement can cause a null pointer exception (NPE) is
if dbCon is not initialized correctly. The logic you present appears to
initialize dbCon in the init() method -- are you certain that no exception is
getting thrown there?
You can put in a simple test to confirm whether this is the problem, by
replacing the above line with:
if (dbCon == null)
System.out.println("dbCon is null!!!");
else
stmt = dbCon.createStatement();
NOTE: You are going to have problems with this code even if you solve the NPE
issue when you have multiple requests to your servlet occuring at the same
time. That would only work if the JDBC driver you use is multithread safe,
which is something I've never heard anyone say about the JDBC-ODBC bridge driver
you are using.
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html