日期:2014-05-18  浏览次数:20830 次

Servlet 创建MYSQL数据库出现错误
我的编程环境为TOMCAT6.0.13,MYSQL5.0,JBUILDER2006,SERVLET   API   2.5,JSDK1.6.0_02-b06,MYSQL的驱动为mysql-connector-java-5.0.7-bin.jar。
在自己的应用程序中的WEB.XML中设置了连接参数:com.mysql.jdbc.Driver,jdbc:mysql://localhost:3306/mysql,root,12345678
在IE中浏览运行出现如下错误:
HTTP   Status   500   -  

--------------------------------------------

type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

javax.servlet.ServletException:   Servlet.init()   for   servlet   CreateDBServlet   threw   exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
java.lang.Thread.run(Unknown   Source)


root   cause  

java.lang.NullPointerException
java.lang.Class.forName0(Native   Method)
java.lang.Class.forName(Unknown   Source)
org.sunxin.lesson.jsp.bookstore.CreateDBServlet.init(CreateDBServlet.java:22)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:852)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:584)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1508)
java.lang.Thread.run(Unknown   Source)


note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/6.0.13   logs.


--------------------------------------------

Apache   Tomcat/6.0.13

------解决方案--------------------
另外,init()函数中取得web.xml中的值是这样子滴::::

String value = getServletContext().getInitParameter( "driverClass ");
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html