2012-08-25 14 views
1

我想检索位于jdk1.7.0_06的数据库服务器JAVA DB上安装的数据。我能够连接到服务器并创建数据库。但我正在编译和运行下面的错误:从日食JAVA DB中的数据检索位于jdk1.7.0_06

No suitable driver found for jdbc:derby:AddressBook 

请你能帮助我!谢谢

+0

您是否为jdbc加载了jdbc驱动程序(例如,在尝试连接之前通过调用Class.forName(“drivername”))? – Pyranja

+0

@Heisenbug,我很早就想起了这个问题。你能告诉我我该怎么做。我喜欢这样做! – Dorji

+0

@Pranranja,我正在练习Deitel在“如何编程”一书中提到的练习,在练习中没有这样的。同时,我想知道上述JDK中的JAVA DB是否包含驱动程序。 – Dorji

回答

2

我说:“我想知道是否需要将derby.system.home属性设置为Java数据库教程的建议。是否尝试过这种方式?System.setProperty("derby.system.home", DERBY_HOME_PATH);其中第二个参数是数据库主目录的路径。

而你回答:

@HovercraftFullOfEels, i think i didn't but i am sure that i have set some envariable variables via command line.

@Dorji:不会在你的JVM设置系统属性虽然。我仍然认为你需要在使用你的数据库之前设置这个属性。例如,

public class Test { 
    public static final String DERBY_HOME = "derby.system.home"; 

    // ***** the two Strings below will be different for you ***** 
    public static final String DERBY_HOME_PATH = "D:/DerbyDB"; 
    private static final String DB_NAME = "sample"; 

    public static void main(String[] args) { 
     System.setProperty(DERBY_HOME, DERBY_HOME_PATH); 
     Connection conn = null; 
     try { 
     Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); 
     conn = DriverManager.getConnection("jdbc:derby:" + DB_NAME); 

     } catch (InstantiationException | IllegalAccessException 
      | ClassNotFoundException | SQLException e) { 
     e.printStackTrace(); 
     } finally { 
     if (conn == null) { 
      System.exit(-1); 
     } 
     } 

     // .... etc... 

我derby.system.home目录是d /:DerbyDB,和我的数据库驻留在d /:DerbyDB /样品目录:

enter image description here

这当然会对你不同。

+0

对不起,迟到的回应。我现在要试试你的。谢谢! – Dorji

+0

我试过了,仍然有相同的错误信息。我有三个名为Person,PersonQueries和AddressBookDisplay的类。你能帮我吗? – Dorji

+0

我仍然面临我找不到的数据库的问题。请问有没有人可以帮助我? – Dorji