Derby: Another instance of Derby may have already loaded the database

I would like to use Derby in network server mode and follow 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

Connection using 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");
   ....
}

Failure 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

Didn't I start a derby in network server mode? Why am I getting this error?

+5
source share
3 answers

Your ij connection:

  connect 'jdbc:derby:testDB';

which means that he did not connect to the network server, but rather opened the database directly using the built-in driver.

If you specified:

  connect 'jdbc:derby://localhost:1527/testDB';

then both applications (IJ and your program) would connect through the client driver, and the second connection would not be rejected.

+6

../metastore_db/dbex.lck .. /metastore _db/db.lck

+6

Although the question already has an answer, in case someone else encounters this error on Glassfish / Payara containers ...

I got this error when restarting the server, as well as when deploying the application, and the problem was that the associated Java process was not killed even after turning off and restarting the server ... destroying the process from the terminal and then starting the application solved the error

0
source

Source: https://habr.com/ru/post/1536356/


All Articles