【发布时间】:2014-06-18 15:09:29
【问题描述】:
我想连接到我计算机上的数据库。我已经创建了一个数据库,但我无法连接。我总是得到一个classnotfoundexception。我不知道如何解决它。我的数据库名为 begindb,我想使用 org.apache.jdbc.ClientDriver 作为驱动程序。这是我程序中的代码:
private final static String JDBC_URL="jdbc:derby://localhost/begindb";
private final static String JDBC_DRIVER="org.apache.derby.jdbc.ClientDriver";
private final static String USER_ID="test";
private final static String PASSW="test";
public static void main(String[] args) {
try{
Class.forName(JDBC_DRIVER);
try(Connection conn = DriverManager.getConnection(JDBC_URL, USER_ID, PASSW)){
System.out.println("good job!!");
}
catch(SQLException e){
System.out.println("Error.");
}
}
catch(ClassNotFoundException e)
System.out.println(e.getMessage());
}
}
因此 try 语句中的第一行将不起作用。因为我得到了一个classnotfoundexception。
【问题讨论】:
-
你的构建路径中有 JDBC 连接器 jar 吗?
-
我不知道,我是第一次尝试这个
-
你在使用 Eclipse 吗?
标签: java database jdbc netbeans derby