摘要:

  Can not read response from server. Expected to read 4  * bytes, read 0 bytes before connection was unexpectedly lost

 

项目出现以上错误。查询资料后发现是连接池的问题,用的dbcp。

mysql5.0之前在连接url后面加 autoReconnect=true参数。5.0之后就必须在mysql配置文件中进行配置了,不推荐。

其实c3p0和其他连接池有一个查询之前先验证的功能,比如druid有validationQuery=true属性。

但是在不换连接池的情况下,我能想到的解决方案是,定义一个查询方法:

    public void validationQuery() {
        try {
            jdbcTemplate.execute("select 1");
        } catch (Exception e) {
        }
    }

在出现错误的查询前,先调用这个方法。

 

以此作为备注!

 

 

 

 

相关文章:

  • 2022-12-23
  • 2022-01-03
  • 2021-09-17
  • 2021-11-19
  • 2021-08-04
  • 2021-08-13
  • 2021-11-17
  • 2022-12-23
猜你喜欢
  • 2021-06-14
  • 2021-06-30
  • 2022-12-23
  • 2022-02-02
  • 2021-09-28
  • 2022-03-08
  • 2021-11-08
相关资源
相似解决方案