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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With