Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutting down derby Network server doesnt delete db.lck

I'm trying to start Derby in Network server mode from my Java application with default port. Server starts successfully. Now I attempt to connect to a DB called 'myDB' on the server. The connection is established and db.lck gets successfully created. I, then, do a couple of transactions, commit and close the connection, gracefully. I see that db.lck is still there. Then I shutdown the network server. I expect db.lck file deleted at the end of all these operations. But it stays. (PS: OS is Windows)

Following is the code:

1) Start the server:

System.setProperty("derby.system.home", "C:\\SI\\testDerby");
System.setProperty("derby.drda.traceDirectory", "C:\\SI\\trace");
System.setProperty("derby.drda.traceAll", "true");
System.setProperty("derby.drda.logConnections", "true");
System.setProperty("derby.connection.requireAuthentication", "false");

serverHandle = new NetworkServerControl();
// Write server console messages to system output
serverHandle.start(new PrintWriter(System.out));

2) Connecting to DB

final String PORT = 1527;
String driver = "org.apache.derby.jdbc.ClientDriver";
String dbName = "myDB";
String connectionURL = "jdbc:derby:" + "//localhost:" 
            + PORT  + "/" + dbName + ";create=true";
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(connectionURL);
Statement stmt = conn.createStatement();
boolean success = stmt.execute("DROP TABLE USERS");
PreparedStatement statement = conn.prepareStatement("CREATE TABLE USERS (id BIGINT not null, name VARCHAR(20))");
success = statement.execute();
conn.commit();
conn.close();

3) Shutting down server

serverHandle.shutdown();

Can anyone please help me out with this ? I need the db.lck file to be deleted when I close the connection or shutdown the DB. I think I'm missing something. Thanks in advance.

like image 206
Kryptic Coder Avatar asked May 18 '11 09:05

Kryptic Coder


People also ask

How do I shutdown a Derby database?

Applications in an embedded environment shut down the Derby system by specifying the shutdown=true attribute in the connection URL. To shut down the system, you do not specify a database name, and you do not ordinarily specify any other attribute.

What is Derby network server?

The Derby Network Server provides multi-user connectivity to Derby databases within a single system or over a network. The Network Server uses the standard Distributed Relational Database Architecture (DRDA) protocol to receive and reply to queries from clients.

How do I connect to a Derby server?

If you want to connect to a Derby database which is running in server mode then you can use the following command. connect 'jdbc:derby://localhost:1527/c:\temp\db\FAQ\db;create=true'; To disconnect from the database.


1 Answers

Perhaps shutting down the server is not shutting down the database; try doing an explicit database shutdown prior to shutting down the server, as described here: http://db.apache.org/derby/docs/10.8/devguide/tdevdvlp40464.html#tdevdvlp40464

like image 108
Bryan Pendleton Avatar answered Nov 15 '22 10:11

Bryan Pendleton