![]() |
createStatement() not recognized
Hello All,
I have 2 classes EstablishDBConnection.java which reads the database connection details from a txt file and then my servlet CustomQuery.java which used the other class to establish the connection and do its servlet stuff But i the second (general) exception in doPost fires Servlet code: :
import java.io.*;establishConnection code :
import java.io.*;Output: Output: java.lang.NullPointerException at EstablishDBConnetion.createStatementObj(EstablishDBConnetion.java:74) at CustomQuery.doPost(CustomQuery.java:66) at CustomQuery.doGet(CustomQuery.java:52) at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:417) at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:131) at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:198) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:138) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2459) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:132) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:593) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:126) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:619) |
Try rebuilding your code. I don't see how it even compiles this line in your servlet's doPost():
:
stmt.createStatement();Because java.sql.Statement has no createStatement() method. You already created a Statement and even if you changed that line to "edbc.createStatementObj()", the return value still is ignored and you dont need another Statement so I don't know why its there. |
thanks, i got rid of that line in my servlet class
and in my other class i changed it to :
Statement stmt = new con.createStatement();so in my servlet i have :
rs = edbc.stmt.executeQuery("SELECT customerID" + and i get this error from apache: HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception java.lang.NullPointerException at CustomQuery.doPost(CustomQuery.java:70) at CustomQuery.doGet(CustomQuery.java:52) at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:417) at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:131) at javax.servlet.http.HttpServlet.service(HttpServlet.java:696) at javax.servlet.http.HttpServlet.service(HttpServlet.java:809) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:198) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:144) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:138) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2459) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:132) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:593) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:593) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:126) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:595) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:432) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:954) at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:619) and java.Sql does have a createStatement() method, its used to create a statement obj. |
Quote:
Quote:
Quote:
|
I put all the connection code in init() of the servlet, but still get a null pointer exceptionat run time (when i run it in apache 4.1) at the line:
stmt = con.createStatement(); I dont see why Code: :
import java.io.*;Apache Output: :
HTTP Status 500 -any ideas ? I have ensured that MySql is running and the connection data looks right |
Output some logging information. Verify that init runs, and verify that it gets to the part where you assign con without throwing an exception. Then verify afterwards that con is not null, and that the correct data was passed to it. (Incidentally, why are you using a text file instead of putting the data in a XML config file?)
|
init() not firing
Hello,
It seems that init() does not fire, thus my connection is never established. I cannot figure out why Here is the updated servlet code: :
import java.io.*;Server and web.xml files can be downloaded from pcwebs.ca/pf/server.xml and pcwebs.ca/pf/web.xml note: as i understand because of the way my server and web.xml (web.xml in the conf directory not web-inf directory) are, all i have to do to deploy is stop the server put my newly compiled class into the installdir/\webapps\ROOT\WEB-INF\classes start the server and access it by http://localhost/servler/ClassName ps: im using a txt file to store the connection details as I dont know XML |
Try:
:
public void init(ServletConfig config) throws ServletException |
thanks but i still get the same result
|
| All times are GMT -5. The time now is 1:41 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC