I am working on a dB viewer for a h2 database in java.
I am using a sample code to try and connect to it as follows:
import java.sql.*;
public class db {
public static void main(String[] a)
throws Exception {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.
getConnection("jdbc:h2:~/test", "sa", "");
// add application code here
conn.close();
}
}
But when I run it I get the following error:
Exception in thread "main" java.lang.ClassNotFoundException: org.h2.Driver at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at db.main(db.java:5)
Any ideas? I have installed h2 using the installer.
org.h2.Driverclass in your classpath.