try{
//把这些都删掉
}
catch(Exception e){
}
finally{
try{
if (result != null)
{
result.close();//最好把结果集清空
}
if(stmt!=null){
stmt.close(); }
if(conn!=null&& !conn.isClosed()){
conn.close(); }
if(dbCon!=null){
dbCon.closeDBConnection(); //这个方法也改改 }
}
catch(Exception e){
}
}
}
//把这些都删掉
}
catch(Exception e){
}
finally{
try{
if (result != null)
{
result.close();//最好把结果集清空
}
if(stmt!=null){
stmt.close(); }
if(conn!=null&& !conn.isClosed()){
conn.close(); }
if(dbCon!=null){
dbCon.closeDBConnection(); //这个方法也改改 }
}
catch(Exception e){
}
}
}
try {
conn = getConnection();
prepareStatement = conn.prepareStatement(sql);
resultSet = prepareStatement.executeQuery();
while (resultSet.next()) {
name = resultSet.getString(1);
}
return name;
}
catch (SQLException e) {
log.error("查询数据失败");
throw e;
}
finally {
release(resultSet,prepareStatement,conn);
}private void release(ResultSet resultSet,PreparedStatement prepareStatement,Connection conn) { try {
if (resultSet != null)
resultSet.close();
}
catch (SQLException e) {
// don't throw Exception
}
try {
if (prepareStatement != null)
prepareStatement.close();
}
catch (SQLException e) {
// don't throw Exception
} try {
if (conn != null)
conn.close();
}catch (SQLException e) {
// don't throw Exception
}
}
}如果实在无法关闭只能依靠荣起来关闭
System.out.println(con.isClosed());