加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

Java JDBC:Reply.fill()

发布时间:2020-12-15 02:59:07 所属栏目:Java 来源:网络整理
导读:我有时会得到以下异常: com.ibm.db2.jcc.b.gm: [jcc][t4][2030][11211][3.50.152] A communication error occurred during operations on the connection’s underlying socket,socket input stream, or socket output stream. Error location: Reply.fill(
我有时会得到以下异常:

com.ibm.db2.jcc.b.gm: [jcc][t4][2030][11211][3.50.152] A communication error occurred during operations on the connection’s underlying socket,socket input stream,
or socket output stream. Error location: Reply.fill(). Message: Connection reset. ERRORCODE=-4499,SQLSTATE=08001

问题是,代码成功执行了一段时间,然后突然我得到了这个异常.但是,当我再次运行代码时,它会正常运行.

有人可以告诉我可能出现的问题并提供一些解决方法.

解决方法

这是未正确关闭/释放JDBC资源的标志.您需要在尽可能短的范围内获取和关闭所有JDBC资源,即您需要在与获取它们完全相同的方法块的try块的finally块中以相反的顺序关闭它们.例如.
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
    connection = database.getConnection();
    statement = connection.createStatement();
    resultSet = statement.executeQuery(SQL);
    // ...
} finally {
    if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {}
    if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {}
    if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
}

如果你没有尽快正确关闭它们,数据库迟早会把它拿在手里,你的应用程序可能会在你遇到自己的时候迟早打破.

要提高连接性能,请使用连接池 – 您仍然需要以与上面相同的方式获取和关闭它们!它现在只是连接池实现,它在引擎盖下担心实际关闭连接.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读