简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM