fail to create embedded derby java

北战南征 提交于 2019-12-11 01:26:56

问题


I created a embedded derby in JDBC mode but when I try to access it in java class it gives me error:

java.sql.SQLException: Failed to create database 'myDB', see the next exception for details.
    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.createDatabase(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:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:207)
    at embededderby.Main.createConnection(Main.java:42)
    at embededderby.Main.main(Main.java:30)

回答1:


First of all,

config your folder to create a Database with:

System.setProperty("derby.system.home", System.getProperty("user.home")
            + "/myDbFolder");

and then

create your database with properties

driverClassName = "org.apache.derby.jdbc.EmbeddedDriver"

url="jdbc:derby:SolofutbolParaguayDB;create=true" //to create a new Db

Example

 public HelloWorld() {

    try {
        setDBSystemDir();
        Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
        Connection dbConnection = null;
        String strUrl = "jdbc:derby:SolofutbolParaguay;create=true";

        try {
            dbConnection = DriverManager.getConnection(strUrl);
            System.out.println("connection created");
            createTable(dbConnection);
            insertRecord(dbConnection);
            listRecord(dbConnection);
            System.out.println("connection close");
        } catch (SQLException sqle) {
            sqle.printStackTrace();
        }

    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

private void setDBSystemDir() {
    // Decide on the db system directory: <userhome>/.addressbook/
    System.setProperty("derby.system.home", "/Users/myuser/futbol



回答2:


When it says "see the next exception for details", here's how to do that: http://wiki.apache.org/db-derby/UnwindExceptionChain



来源:https://stackoverflow.com/questions/4999106/fail-to-create-embedded-derby-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!