【问题标题】:how to fix h2 Database may be already in use,Cannot invoke "java.sql.Connection.prepareStatement(String)" because "this.connectore.connection" is null [duplicate]如何修复 h2 数据库可能已经在使用中,无法调用 \"java.sql.Connection.prepareStatement(String)\" 因为 \"this.connectore.connection\" 为空 [重复]
【发布时间】:2023-02-22 21:32:28
【问题描述】:

一开始连接正常,但在使用应用程序一段时间后(比如一个小时),它停止了,我得到了错误: “org.h2.jdbc.JdbcSQLNonTransientConnectionException:数据库可能已在使用中:“C:/Users/Setup Game/eclipse-workspace/eclipse java D/Gestion/test/Database/les.mv.db”。可能的解决方案:关闭所有其他连接;使用服务器模式 [90020-214] java.lang.NullPointerException:无法调用“java.sql.Connection.prepareStatement(String)”,因为“this.connectore.connection”为空 它随机停止并返回 null 尽管非按钮代码导致它崩溃,一开始一切正常 这是我的代码:

Class.forName("org.h2.Driver");
            connection = DriverManager.getConnection("jdbc:h2:"+"./test/Database/les","root","");
stmStatement = connection.createStatement();
String sql = "create table IF NOT EXISTS info("
        + "n_dossier varchar(20) not null primary key,"
        + "    nom varchar(100) not null";
        stmStatement.executeUpdate(sql);
connection.prepareStatement("BACKUP TO './test/backup.zip'").executeUpdate();

如果我删除数据文件并休息它再次工作正常

【问题讨论】:

标签: java jdbc h2


【解决方案1】:

您是否在每次查询后关闭连接? 有时错误是因为打开了太多连接。

connection.close(); 可以帮助你。

【讨论】:

  • 我没有 我会试着回复你
猜你喜欢
  • 2021-04-29
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 2022-10-21
  • 2021-12-20
  • 2021-12-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多