我正在尝试使用H2连接到Java中的数据库(使用Eclipse作为IDE).样本确实(下面)抛出一个ClassNotFoundException.问题是,我确实将h2 jar文件添加到系统CLASSPATH中.我甚printenv至在控制台中检查了几次.我省略了一步吗?
码:
import java.sql.*;
public class Program {
/**
* @param args
*/
public static void main(String[] args)
throws Exception{
try{
System.out.println("hello, world!");
Class.forName("org.h2.Driver");
Connection conn = DriverManager.getConnection("jdbc:h2:~/testdb", "sa", "");
// add application code here
conn.close();
}catch(ClassNotFoundException ex){
System.out.println( "ERROR: Class not found: " + ex.getMessage() );
}
System.exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)