2
java.sql.SQLException:找不到適合jdbc:h2:tcp:// localhost /〜/ ZadatakDB的驅動程序,當我嘗試連接到h2數據庫時使用java web應用程序。沒有找到適用於jdbc的驅動程序:h2:tcp
我可以使用H2控制檯沒有任何問題,並且ping是成功的。
我還將h2-1.3.176 jar文件添加到庫和WEB-INF/lib中。
這裏是我的Java方法我使用的連接:
private static Connection connectToDatabase() throws SQLException,
IOException {
String url = "jdbc:h2:tcp://localhost/~/ZadatakDB";
String username = "student";
String pw = "student";
Connection connection = DriverManager.getConnection(url,
username, pw);
return connection;
}
什麼可能我會丟失?
我也將增加堆棧跟蹤:
java.sql.SQLException: No suitable driver found for jdbc:h2:tcp://localhost/~/ZadatakDB
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at hr.web.aplikacija.DatabaseUtils.connectToDatabase(DatabaseUtils.java:20)
at hr.web.aplikacija.DatabaseUtils.insertForm(DatabaseUtils.java:38)
at hr.web.aplikacije.servlet.KorisnikServlet.doPost(KorisnikServlet.java:68)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
您在堆棧跟蹤中有ClassNotFound異常嗎? –
我沒有,我只有SQL異常 – Sarpy
如果您使用:Class.forName(「org.h2.Driver」)。newInstance();在你的方法的第一行?它應該在DriverManager中註冊所需的驅動程序。 –