在尝试运行我的程序时,我不断收到此异常:

时间:2014-03-18 17:06:34

标签: java derby

Die Datenbank 'C:\TEMP\derbyDB01' konnte nicht mit dem Klassenladeprogramm sun.misc.Launcher$AppClassLoader@253498 gestartet werden. Details können Sie der nächsten Ausnahme entnehmen.
    at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
    at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
    at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
    at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
    at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
    at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:243)
    at Importer.getCon(Importer.java:88)

这是代码的一部分,导致异常:

private static final String jdbc_driver = "org.apache.derby.jdbc.EmbeddedDriver";
private static Connection conn = null;

public void importToDB(String DB_URL, String[] header, List<Data> dataList, File csv ) throws SQLException, ClassNotFoundException {
    stmt = null;
    ResultSet rs = null;
    String sql = null;
    String tablename = spl.getTableName(csv);

        Class.forName(jdbc_driver);

        if (conn == null) {

            conn = getCon(DB_URL);
        }

...

public static Connection getCon(String DB_URL) throws SQLException {

        System.out.println("Connecting to a selected database...");

        conn = DriverManager.getConnection(DB_URL);

        System.out.println("Connected successfully...");
        return conn;

    }

通过从JTextfield获取字符串DB_URL给予该方法。我使用的URL是正确的,因为程序在添加GUI之前使用它。它是:&#34; jdbc:derby:C:\ TEMP \ derbyDB01&#34;

那么是什么导致了这么多问题?

2 个答案:

答案 0 :(得分:0)

根据Derby developer guide,您需要反转网址

中的斜杠
jdbc:derby:c:/TEMP/derbyDB01

答案 1 :(得分:0)

很抱歉花了这么长时间来更新此内容。

几乎忘了我把它贴在这里了。问题是我通过eclipse db插件打开了数据库连接。关闭该插件时,它不会正确关闭连接,然后在程序尝试时会在此异常中产生再次访问。