开发者

fail to create embedded derby java

开发者 https://www.devze.com 2023-02-11 00:55 出处:网络
I created a embedded derby in JDBCmode 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 excepti开发者_StackOverflow

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 excepti开发者_StackOverflow社区on 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)


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消