I read some other answers, but cannot solve the problem.
I am using NetBeans 7.0.1 and the latest version of H2 DB on Win7.
I successfully use the H2 console tool and also added a driver to NetBeans and can connect (see DB table, tables, release commands, etc.). However, from my Java code, when I run 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 also added the H2 file of the file to the class path (although I had to create a path to the class itself and point to the jar file) - I switched to environment variables → user variables
name=classpath value=.;C:\NetBeansProjects\testdemo\src\testdemo\DB\h2-1.3.165.jar
What am I doing wrong?
source
share