Skip to content
Advertisement

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

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?

Advertisement

Answer

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.

Advertisement