Derby: Another instance of Derby may have already booted the database
Asked Answered
B

4

9

I would like to use Derby in a Network Server Mode and followed the instructions on their website.

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:

$ /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:

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:

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?

Brass answered 13/4, 2014 at 22:13 Comment(0)
V
8

Your ij connection did:

  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.

Veneering answered 14/4, 2014 at 4:6 Comment(0)
J
14

delete the below files

../metastore_db/dbex.lck and ../metastore_db/db.lck

Thanks

Jugum answered 13/9, 2016 at 9:17 Comment(0)
V
8

Your ij connection did:

  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.

Veneering answered 14/4, 2014 at 4:6 Comment(0)
M
2

Although the question is answered already, just in case someone else encounters this error on glassfish/payara containers...

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

Modish answered 18/12, 2018 at 7:14 Comment(1)
The database should be shutdown properly. Try registering ServletContextListener and inside its 'contextDestroyed()' method call: DriverManager.getConnection("jdbc:derby:mydatabase;shutdown=true");. This will throw informative exception which you can ignore.Smilacaceous
V
0

if your computer crash when nacos server is running, the dbex.lck and db.lck under nacos direcotory don't release normally which cause this situation,you need delete dbex.lck and db.lck ,it works!!

Varietal answered 26/5, 2022 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.