Hello Ranchers,
I have tried searching around for the answer to this for hours but could not find a solution so hopefully someone can help. I have created an application which sends values to a Data Access Object from a
test class. I used a DBConnectionFactory to setup up the connections etc. That all worked perfectly but it was until I had to use it with a
jsp is the problem.
I copied the code from my test class which worked and used it in the jsp like so:
The webpage appears, i enter in the details and submit them and then i get the following error message. (Using
Tomcat server)
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /adduser.jsp at line 201
198: usr.setCountry(country);
199: usr.setType(type);
200:
201: usrDAO.insert(usr);
202:
203: }
204:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
root cause
java.lang.NullPointerException
investmentclub.UserDAO.insert(UserDAO.java:126)
org.apache.jsp.adduser_jsp._jspService(adduser_jsp.java:255)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)
So I check the UserDAO class and it says the null pointer exception is at the Statement st = conn.createStatement(); line. (Below)
Like I have said I tried searching for similar problems for hours on the net and the only solutions i found were that people made spelling mistakes which isn't my problem. I apologise if it is something trivial or obvious but sometimes you need the obvious pointed out!
Hope to hear from someone soon,
Mike.