DBUtils关闭连接

问题:

使用DBUtils写了一个分页,在多次快速点击之后报错。

报错内容:

no connection

问题定位

最终将问题定位到dao层
下面的这种语句

queryRunner.query(JdbcUtil.getConnection,sql,new BeanListHandler<Category>(Category.class));

方法需要的connection对象,通过工具类直接获得,没有关闭连接,最终造成报错的现象出现。

解决方法:

//通过工具类获得connection连接和关闭connection连接
Connection connection = JdbcUtil.getConnection();
JdbcUtil.closeDB(null, null, connection);

tips:

query方法自动关闭preparedStatement流和ResultSet流,但是不自动关闭connection连接

猜你喜欢

转载自blog.csdn.net/hotchange/article/details/80952769