propStream = SqlHelper.class.getClassLoader()
.getResourceAsStream("dbinfo.properties prop.load(propStream);
driver = prop.getProperty("driver");
url = prop.getProperty("url");
username = prop.getProperty("username");
password = prop.getProperty("password");
Class.forName("com.mysql.jdbc.driver");");
自从添加了propStream = SqlHelper.class.getClassLoader()
.getResourceAsStream("dbinfo.properties");后就发生
java.lang.ClassNotFoundException: com.mysql.jdbc.driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1438)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.skybird.util.SqlHelper.<clinit>(SqlHelper.java:47)
at com.skybird.model.UserService.checkUser(UserService.java:25)
at com.skybird.controller.LoginVerify.doPost(LoginVerify.java:47)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:881)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:674)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:541)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689) at java.lang.Thread.run(Unknown Source)
错误,但是在tomcat bin目录下已经有mysql的连接驱动,并且查询数据库可以正常使用,只是报有这个错误,怀疑是SqlHelper.class.getClassLoader()加载的问题,请各位给看看神马原因?????
------最佳解决方案--------------------
Class.forName()的参数是不是错了?
------其他解决方案--------------------
那你试试,直接将数据写死,看能连接吗?一步步排除错误,走断点
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException e) {}
//定义所要用到的三个数据库应用对象
Connection con=null; //连接对象
Statement sql=null; //Statement对象(SQL语句)
//进行数据源的连接
try{
con=DriverManager.getConnection ("jdbc:mysql://localhost/scutcs","","");//连接数据库的url 用户名和密码
sql=con.createStatement();
catch (SQLException e)
{ out.print(e);
}
------其他解决方案--------------------
Class.forName("com.mysql.jdbc.driver");");