这篇文章主要讲解了“jdbc怎么让连接关闭”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“jdbc怎么让连接关闭”吧!
public Boolean exeUpdateSql(String sql){
// log.info("cliockhouse 执行更新sql:" + sql);
Connection connection = getConn();
Statement statement = null;
ResultSet results=null;
try {
statement = connection.createStatement();
results = statement.executeQuery(sql);
return true;
} catch (Exception e) {
e.printStackTrace();
MyExceptionUtils.getExceptionInfo(e);
return false;
}finally {
if(connection!=null){
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
connection = null;
}
if(results!=null){
try {
results.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
results = null;
}
if(statement!=null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
return false;
}
statement = null;
}
}
}
感谢各位的阅读,以上就是“jdbc怎么让连接关闭”的内容了,经过本文的学习后,相信大家对jdbc怎么让连接关闭这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是天达云,小编将为大家推送更多相关知识点的文章,欢迎关注!