关闭 derby Network 服务器不会删除 db.lck

发布于 2024-11-08 04:02:52 字数 1471 浏览 0 评论 0原文

我正在尝试从我的 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 文件。我想我错过了一些东西。提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所的.畏惧 2024-11-15 04:02:52

也许关闭服务器并没有关闭数据库;尝试在关闭服务器之前执行显式数据库关闭,如下所述:http://db.apache.org/derby/docs/10.8/devguide/tdevdvlp40464.html#tdevdvlp40464

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文