简体   繁体   中英

I keep getting this Exception when trying to run my program:

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)

this is the part of the code, causing the exception:

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;

    }

the String DB_URL is given to the method by taking it from a JTextfield. the URL I use is correct, because the program worked with it, before adding the GUI. it is: "jdbc:derby:C:\\TEMP\\derbyDB01"

So what is causing so much problems in here?

根据Derby开发人员指南 ,您需要在URL中反斜杠

jdbc:derby:c:/TEMP/derbyDB01

Sorry for taking so long to Update this.

Almost forgot I had it posted here. The problem was that I opened the database connection via an eclipse db plugin. When closing that plugin, it doesn't properly close the connection, which then produces in this exception when the program is trying do gain access again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM