H2 driver not found when try to connect

蹲街弑〆低调 提交于 2020-01-03 10:01:49

问题


I have gone through some other answers, but cannot get the solution to my problem.

I am using NetBeans 7.0.1 and the latest version of the H2 DB on Win7.

I successfully use the H2 console tool and I have also added the driver in NetBeans and am able to connect (i.e. see the DB, tables, issue commands, etc). However from within my Java code when running it, I get the message: "java.lang.ClassNotFoundException:org.h2.Driver". My code is:

Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:tcp://localhost/~/testDB", "sa", "");
Statement query = null;
query = conn.createStatement();
String firstString = "INSERT INTO ......";
query.executeUpdate(firstString);

I have also added the H2 jar file in the classpath (although I had to create the classpath myself and point to the jar file) - I went to environment variables -> user variables

name=classpath value=.;C:\NetBeansProjects\testdemo\src\testdemo\DB\h2-1.3.165.jar

What am I doing wrong?


回答1:


Add the H2 jar file in the "Libraries" section under the source code packages.




回答2:


Change parent version

spring-boot-starter-parent 1.4.3.RELEASE



来源:https://stackoverflow.com/questions/9987525/h2-driver-not-found-when-try-to-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!