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?

4 Answers4

14

delete the below files

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

Thanks

Krishna Pratap
  • 221
  • 3
  • 7
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.

Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
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

denizdurmus
  • 1,289
  • 1
  • 13
  • 39
  • 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. – Dimitar II Nov 07 '19 at 15:21
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!!