java 连接到 Derby 网络服务器时数据库未找到错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17375504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Database not found error when connecting to Derby network server
提问by Nepze Tyson
I'm having problems initializing my javadb network server and setting a connection to it. It's a JavaFX program.
我在初始化我的 javadb 网络服务器并设置到它的连接时遇到问题。这是一个 JavaFX 程序。
This is what I have so far:
这是我到目前为止:
try {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
javadbserver = new NetworkServerControl();
javadbserver.start(null);
} catch (ClassNotFoundException e) {
Logger.getLogger(MainGuiController.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("Where is your JavaDB embedded Driver?");
return;
}
String dbName = "mydb";
String dbUser = "auser";
String dbPass = "password";
PreparedStatement prepstmt;
try {
this.conn = DriverManager.getConnection("jdbc:derby://localhost:1527/mydb;user=auser;password=password");
System.out.println("Went through!");
} catch (SQLException ex) {
Logger.getLogger(MainGuiController.class.getName()).log(Level.SEVERE, null, ex);
}
I always catch the second exception.
我总是捕捉到第二个异常。
If I right click on the javadb service in netbeans and choose connect, everything runs smoothly. [Actually it'd be nice to know what code or program java runs in the background when I select that]
如果我在 netbeans 中右键单击 javadb 服务并选择连接,则一切运行顺利。[实际上,当我选择它时,知道 java 在后台运行什么代码或程序会很好]
In my projects list under libraries I see derby.jar, derbyclient.jar and derbynet.jar
在库下的我的项目列表中,我看到 derby.jar、derbyclient.jar 和 derbynet.jar
What am I doing wrong? Please help!
我究竟做错了什么?请帮忙!
Here's the error I get
这是我得到的错误
java.sql.SQLNonTransientConnectionException: The connection was refused because the database mydb was not found.
at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:243)
at mydb.MainGuiController.initialize(MainGuiController.java:105)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2152)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at mydb.mydb.start(mydb.java:37)
at com.sun.javafx.application.LauncherImpl.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.run(PlatformImpl.java:176)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access0(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
Caused by: org.apache.derby.client.am.DisconnectException: The connection was refused because the database mydb was not found.
at org.apache.derby.client.net.NetConnectionReply.parseRDBNFNRM(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseAccessRdbError(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.parseACCRDBreply(Unknown Source)
at org.apache.derby.client.net.NetConnectionReply.readAccessDatabase(Unknown Source)
at org.apache.derby.client.net.NetConnection.readSecurityCheckAndAccessRdb(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowSecurityCheckAndAccessRdb(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source)
at org.apache.derby.client.net.NetConnection.<init>(Unknown Source)
at org.apache.derby.client.net.NetConnection40.<init>(Unknown Source)
at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl40.newNetConnection(Unknown Source)
回答by ikumen
By the JDBC url, it's looks like you're trying to connect to a Derby server vs. an embedded instance. If you are trying to connect to a server instance, here are some considerations:
通过 JDBC url,您似乎正在尝试连接到 Derby 服务器而不是嵌入式实例。如果您尝试连接到服务器实例,请注意以下几点:
- did you start the server yourself, did mydb already exists?
- if not, did you pass in the correct params to create (e.g. ;create=true)
example: jdbc:derby://localhost:1527/dbname;create=true
- if mydb did exists, are you pointing the server to the correct location?
- also, depending on what was used to start derby (e.g. embedded vs network driver) default database locations are different as well. You can read about it here
- 你自己启动了服务器,mydb 已经存在了吗?
- 如果没有,您是否传入了正确的参数来创建(例如;create=true)
example: jdbc:derby://localhost:1527/dbname;create=true
- 如果 mydb 确实存在,您是否将服务器指向正确的位置?
- 此外,根据用于启动 derby 的内容(例如嵌入式驱动程序与网络驱动程序),默认数据库位置也不同。你可以在这里阅读
Basically the exception you're getting is that Derby's saying it can't find your database - it's basically a path issue.
基本上你得到的例外是德比说它找不到你的数据库 - 这基本上是一个路径问题。
回答by SanchelliosProg
If you're using netbeans, you should fix this by going into the connection properties and adding a property. Under "property" type "create" and under "value" type "true".
如果您使用的是 netbeans,您应该通过进入连接属性并添加一个属性来解决这个问题。在“属性”下输入“创建”,在“值”下输入“真”。