本文介绍了无法创建嵌入式derby Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JDBC模式下创建了一个嵌入式derby,但是当我尝试在java类中访问它时,却给了我错误:
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)
推荐答案
首先,
System.setProperty("derby.system.home", System.getProperty("user.home")
+ "/myDbFolder");
然后
driverClassName = org.apache.derby.jdbc.EmbeddedDriver
driverClassName = "org.apache.derby.jdbc.EmbeddedDriver"
url = jdbc:derby :SolofutbolParaguayDB; create = true //创建新的Db
url="jdbc:derby:SolofutbolParaguayDB;create=true" //to create a new Db
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
这篇关于无法创建嵌入式derby Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!