当我尝试从servlet连接到我的MYSQL数据库时出现以下错误。但是,当我从独立应用程序访问数据库时,这不会发生。
Dec 20, 2014 1:31:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:NbaFantasyApp' did not find a matching property.
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.57
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Nov 3 2014 08:39:16 UTC
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.57.0
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JAVA_HOME: C:\Program Files\Java\jre1.8.0_25
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_25-b18
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\PC\workspace_EE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Users\PC\Documents\eclipse-jee-luna-SR1-win32-x86_64\apache-tomcat-7.0.57\apache-tomcat-7.0.57
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\PC\workspace_EE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Users\PC\Documents\eclipse-jee-luna-SR1-win32-x86_64\apache-tomcat-7.0.57\apache-tomcat-7.0.57
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\PC\workspace_EE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Users\PC\Documents\eclipse-jee-luna-SR1-win32-x86_64\apache-tomcat-7.0.57\apache-tomcat-7.0.57\endorsed
Dec 20, 2014 1:31:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Dec 20, 2014 1:31:00 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_25\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk1.8.0_25\bin;C:\Program Files\MySQL\MySQL Server 5.6\bin;.
Dec 20, 2014 1:31:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Dec 20, 2014 1:31:01 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Dec 20, 2014 1:31:01 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 363 ms
Dec 20, 2014 1:31:01 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 20, 2014 1:31:01 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.57
Dec 20, 2014 1:31:01 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Dec 20, 2014 1:31:01 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Dec 20, 2014 1:31:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 392 ms
java.lang.ClassNotFoundException: com.mysql.jdbc.driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.nba.fanduel.controller.ConnectionTest.doGet(ConnectionTest.java:36)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
这是我在servlet中的doGet()方法内的代码。这个相同的代码在独立应用程序的主方法中运行良好。不确定为什么在servlet中发生这种情况。请帮助,谢谢。
try{
Class.forName("com.mysql.jdbc.driver");
final String URL = "jdbc:mysql://localhost:3306/nbaplayers";
final String user = "root";
final String pass = "password";
System.out.println("Connecting");
Connection conn = DriverManager.getConnection(URL,user,pass);
System.out.println("connection Successful ");
String sql = "select * from nba_player_consistency_3wks";
}catch(SQLException ex){
ex.printStackTrace();
}catch(ClassNotFoundException ex){
ex.printStackTrace();
}
}
答案 0 :(得分:0)
试试这个(用大写字母D):
Class.forName("com.mysql.jdbc.Driver");