无法创建嵌入式 derby java

发布于 2024-10-17 13:14:47 字数 1185 浏览 1 评论 0原文

我在 JDBC 模式下创建了一个嵌入式 derby,但是当我尝试在 java 类中访问它时,出现错误:

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘿咻 2024-10-24 13:14:47

首先,

配置您的文件夹以创建数据库:

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

然后

使用属性

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

url="jdbc:derby:SolofutbolParaguayDB;create=true" //创建数据库一个新的数据库

示例

 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

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
悲欢浪云 2024-10-24 13:14:47

当它说“查看下一个异常以获取详细信息”时,具体操作方法如下: http://wiki .apache.org/db-derby/UnwindExceptionChain

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文