Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H2 driver not found when try to connect

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?

like image 692
user1304490 Avatar asked Apr 03 '12 05:04

user1304490


People also ask

What is H2 driver?

H2 is an open-source lightweight Java database. It can be embedded in Java applications or run in the client-server mode. Mainly, H2 database can be configured to run as inmemory database, which means that data will not persist on the disk.


1 Answers

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

like image 186
Thomas Mueller Avatar answered Sep 23 '22 02:09

Thomas Mueller