问题描述
出现这个样的错误该怎么样解决啊,网上说的不太明白是什么意思org.apache.catalina.core.StandardWrapperValveinvoke我的连接数据库这样写的packageorg.zjy.db;importjava.sql.*;//该用来负责与数据库之间的连接,同时执行Sql语句publicclassDBUtil{privatestaticConnectionconn=null;privatestaticStatementst=null;//该方法用来获取与数据之间的连接publicstaticConnectiongetConnection(){if(conn==null){try{Class.forName("com.mysql.jdbc.Driver");Stringusername="root";Stringpassword="rychel";Stringurl="jdbc:mysql://localhost:3306/blog";conn=DriverManager.getConnection(url,username,password);}catch(Exceptionex){ex.printStackTrace();}}returnconn;}//该方法用来获取执行Sql语句对象publicstaticStatementgetStatement(){if(st==null){try{Connectionc=getConnection();st=c.createStatement();}catch(Exceptionex){ex.printStackTrace();}}returnst;}//如果Sql语句是Select语句,则外界可以调用该方法来执行publicstaticResultSetexecuteQuery(Stringsql){ResultSetset=null;try{Statementstate=getStatement();set=state.executeQuery(sql);}catch(Exceptionex){ex.printStackTrace();}returnset;}//如果Sql语句是insert,update,delete语句,则外界可以调用该方法来执行publicstaticintexecuteUpdateInsertDelete(Stringsql){inti=0;try{Statementstate=getStatement();i=state.executeUpdate(sql);}catch(Exceptionex){ex.printStackTrace();}returni;}//该方法用来获取外界所给定表中id列当前最的值publicstaticintgetMaxId(StringtableName){StringBuffersql=newStringBuffer();sql.append("selectidfrom"+tableName+"orderbyiddesc;");inti=0;ResultSetset=executeQuery(sql.toString());try{while(set.next()){i=set.getInt("id");break;}}catch(Exceptionex){ex.printStackTrace();}returni;}}下面是出现错误的信息。。2011-3-140:10:40org.apache.catalina.core.AprLifecycleListenerinit信息:LoadedApacheTomcatNativelibrary1.1.14.2011-3-140:10:40org.apache.catalina.core.AprLifecycleListenerinit信息:APRcapabilities:IPv6[false],sendfile[true],acceptfilters[false],random[true].2011-3-140:10:40org.apache.coyote.http11.Http11AprProtocolinit信息:InitializingCoyoteHTTP/1.1onhttp-80902011-3-140:10:40org.apache.coyote.ajp.AjpAprProtocolinit信息:InitializingCoyoteAJP/1.3onajp-80092011-3-140:10:40org.apache.catalina.startup.Catalinaload信息:Initializationprocessedin1252ms2011-3-140:10:40org.apache.catalina.core.StandardServicestart信息:StartingserviceCatalina2011-3-140:10:40org.apache.catalina.core.StandardEnginestart信息:StartingServletEngine:ApacheTomcat/6.0.142011-3-140:10:41org.apache.catalina.core.ApplicationContextlog信息:ContextListener:contextInitialized()2011-3-140:10:41org.apache.catalina.core.ApplicationContextlog信息:SessionListener:contextInitialized()2011-3-140:10:42org.apache.coyote.http11.Http11AprProtocolstart信息:StartingCoyoteHTTP/1.1onhttp-80902011-3-140:10:42org.apache.coyote.ajp.AjpAprProtocolstart信息:StartingCoyoteAJP/1.3onajp-80092011-3-140:10:42org.apache.catalina.startup.Catalinastart信息:Serverstartupin1642mstop.jsp的Blog对象为空2011-3-140:10:53org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.apache.jsp.left_jsp._jspService(left_jsp.java:108)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)atjava.lang.Thread.run(Thread.java:619)2011-3-140:10:53org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.apache.jsp.top_jsp._jspService(top_jsp.java:91)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)atjava.lang.Thread.run(Thread.java:619)2011-3-140:10:53org.apache.catalina.core.StandardWrapperValveinvoke严重:Servlet.service()forservletjspthrewexceptionjava.lang.NullPointerExceptionatorg.apache.jsp.main_jsp._jspService(main_jsp.java:66)atorg.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)atorg.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)atorg.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:803)atorg.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)atorg.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)atorg.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)atorg.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)atorg.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)atorg.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)atjava.lang.Thread.run(Thread.java:619)
解决方案
解决方案二:
怎么还在用jdbc操作连接数据库?你没有学习Hibernate吗??
解决方案三:
//该方法用来获取外界所给定表中id列当前最的值publicstaticintgetMaxId(StringtableName){StringBuffersql=newStringBuffer();sql.append("selectidfrom"+tableName+"orderbyiddesc;");inti=0;ResultSetset=executeQuery(sql.toString());try{while(set.next()){i=set.getInt("id");break;}}catch(Exceptionex){ex.printStackTrace();}returni;}}你这代码问题百出,你的sql语句查询出的是多条Id,但是你只用一个i来接收??你要查最大Id,sql里面应该用max()函数
解决方案四:
引用楼主forgettable的回复:
出现这个样的错误该怎么样解决啊,网上说的不太明白是什么意思org.apache.catalina.core.StandardWrapperValveinvoke我的连接数据库这样写的packageorg.zjy.db;importjava.sql.*;//该用来负责与数据库之间的连接,同时执行Sql语句publicclassDBUtil{privates……
额,这是老师给的例子,让我们参考的
解决方案五:
我看错误信息不是报了一个空指针错误吗??你先改了那个再看一下错误!!!
解决方案六:
该回复于2011-03-14 12:26:28被版主删除
解决方案七:
该回复于2011-03-14 12:26:44被版主删除