德比:当前没有连接?

发布于 2024-12-27 09:10:58 字数 139 浏览 1 评论 0原文

我正在使用 derby 作为数据库。我的正常插入/更新操作工作正常。但有时在插入查询时我收到“无当前连接”错误消息。

我搜索了它但没有找到正确的解决方案。

有谁知道为什么会发生这种异常?

谢谢泰吉

I am using derby for database. and my normal insert/update operation is working fine. But some times while insert query I am getting "No Current Connect" error message.

I searched about it but not found proper solution.

Do any one knows why this exception occurred ?

Thanks

Tej

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

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

发布评论

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

评论(1

清风疏影 2025-01-03 09:10:58

当您尝试在关闭的连接对象上执行操作时会导致此问题。
因此,您需要检查连接是否已关闭,如果是,则再次连接:-

public Connection getConnection() throws SQLException {
    if(connection==null || connection.isClosed()) {
        connect();
    }
    return connection;
}

private void connect() throws SQLException {
    try {
        connection = DriverManager.getConnection(DBURL);
        logger.info("database connection established");
    } catch (SQLException e) {
        logger.error(e.getMessage());
        throw e;
    }
}

its caused when you are trying to execute operations on a closed connection object.
So you need to check if the connection is closed, if so ..then connect again:-

public Connection getConnection() throws SQLException {
    if(connection==null || connection.isClosed()) {
        connect();
    }
    return connection;
}

private void connect() throws SQLException {
    try {
        connection = DriverManager.getConnection(DBURL);
        logger.info("database connection established");
    } catch (SQLException e) {
        logger.error(e.getMessage());
        throw e;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文