问题
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