我想知道为什么我不能在java数据库程序中做最简单的一步!我以前做过很多次,这次我正在做接缝程序,但它不起作用。
我正在尝试以嵌入式模式创建数据库。我在 seam 目录中找到了 derby.jar 文件。这是代码,之后是错误:
public static void main(String[] args) throws SQLException {
String driver ="org.apache.derby.jdbc.EmbeddedDriver";
String url= "jdbc:derby:MyDatabase";
try {
Class.forName(driver).newInstance();
} catch (InstantiationException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
Connection conn = DriverManager.getConnection(url+";create=true");
}
这是错误:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at Data.main(Data.java:16)
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:derby:MyDatabase;create=true
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at Data.main(Data.java:27)