【发布时间】:2011-05-18 09:30:40
【问题描述】:
我正在尝试使用默认端口从我的 Java 应用程序以网络服务器模式启动 Derby。服务器启动成功。现在我尝试连接到服务器上名为“myDB”的数据库。连接已建立,db.lck 已成功创建。然后,我进行了一些事务,优雅地提交并关闭连接。我看到 db.lck 仍然存在。然后我关闭了网络服务器。我希望在所有这些操作结束时删除 db.lck 文件。但它仍然存在。 (PS:操作系统是Windows)
以下是代码:
1) 启动服务器:
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) 连接数据库
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) 关闭服务器
serverHandle.shutdown();
谁能帮我解决这个问题?当我关闭连接或关闭数据库时,我需要删除 db.lck 文件。我想我错过了一些东西。提前致谢。
【问题讨论】: