Java Derby:另一个 Derby 实例可能已经启动了数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23049078/
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
Derby: Another instance of Derby may have already booted the database
提问by
I would like to use Derby in a Network Server Mode and followed the instructions on their website.
我想在网络服务器模式下使用 Derby,并按照他们网站上的说明进行操作。
Starting derby:
德比开局:
/opt/glassfish/4.0/javadb/bin/NetworkServerControl start -noSecurityManager
Sun Apr 13 23:47:57 CEST 2014 : Apache Derby Network Server - 10.9.1.0 - (1344872) started and ready to accept connections on port 1527
Connecting with ij
:
连接ij
:
$ /opt/glassfish/4.0/javadb/bin/ij
ij version 10.9
ij> connect 'jdbc:derby:testDB';
ij> create table testt ( x varchar(200), y varchar(200), z varchar(13));
0 rows inserted/updated/deleted
ij> select * from testt;
X
|Y
|Z
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0 rows selected
ij> commit;
ij>
Connecting to Derby in Java:
在 Java 中连接到 Derby:
static{
try {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
} catch (Throwable e) {
e.printStackTrace();
}
}
public void readData(){
final Connection connection = DriverManager.getConnection("jdbc:derby://localhost:1527/testDB");
....
}
The DriverManager.getConnection()
is failing with:
DriverManager.getConnection()
失败的是:
java.sql.SQLException: DERBY SQL error: SQLCODE: -1, SQLSTATE: XJ040,
SQLERRMC: Failed to start database 'testDB' with class loader sun.misc.Launcher$AppClassLoader@23137792, see the next exception for details.::
SQLSTATE: XSDB6Another instance of Derby may have already booted the database
Haven't I just started derby in network server mode? Why am I getting this error?
我不是刚刚在网络服务器模式下启动了 derby 吗?为什么我收到这个错误?
采纳答案by Bryan Pendleton
Your ij connection did:
您的 ij 连接做了:
connect 'jdbc:derby:testDB';
which means that it didn't connect to the Network Server, but rather opened the database directly using the Embedded Driver.
这意味着它没有连接到网络服务器,而是直接使用嵌入式驱动程序打开数据库。
If you had specified:
如果您已指定:
connect 'jdbc:derby://localhost:1527/testDB';
then both applications (IJ and your program) would have connected via the Client Driver and the second connection would not have been rejected.
那么两个应用程序(IJ 和您的程序)都将通过客户端驱动程序连接,并且第二个连接不会被拒绝。
回答by Krishna Pratap
delete the below files
删除以下文件
../metastore_db/dbex.lck and ../metastore_db/db.lck
../metastore_db/dbex.lck 和 ../metastore_db/db.lck
Thanks
谢谢
回答by denizdurmus
Although the question is answered already, just in case someone else encounters this error on glassfish/payara containers...
虽然这个问题已经回答了,以防万一其他人在 glassfish/payara 容器上遇到这个错误......
I was getting this error on server restart, and while deploying an application as well, and problem was the related java process was not killed even after a server shutdown and restart... killing the process from the terminal and then starting the application solved the error
我在服务器重启时遇到这个错误,在部署应用程序时,问题是即使在服务器关闭并重启后相关的 java 进程也没有被杀死......从终端杀死进程然后启动应用程序解决了错误