public boolean isAuditTrailEnabled(String masterAccessId)
{
String selectQuery = "select t.audit_flag from PARAMETER_MENU_ATTRIBUTES t where t.access_id = '"+masterAccessId+"'";
PreparedStatement preparedStmnt = null;
ResultSet resultSet = null;
String flag = "N";
if(connection == null)
{
initConnection();
}
try {
**preparedStmnt = connection.prepareStatement(selectQuery);**
resultSet = preparedStmnt.executeQuery();
if(resultSet.next())
{
flag = resultSet.getString(1);
}
}
catch (SQLException e) {
try {
if (resultSet != null){
resultSet.close();
}
if (preparedStmnt != null){
preparedStmnt.close();
}
} catch (SQLException e1) {
}
return true;
}
finally{
try {
if (resultSet != null){
resultSet.close();
}
if (preparedStmnt != null){
preparedStmnt.close();
}
cleanup();
} catch (SQLException e1) {
return false;
}
}
if(flag.equals("N")){
return false;
}else{
return true;
}
}
它显示了该特定语句的问题。你能帮我一下吗?
最佳答案
结果集和语句始终应该在单独的 try catch 中关闭...甚至 2 if 不能以这种方式编写...它应该在第一个 if 中循环...或者保留 else if...首先检查基础知识 if 条件
if(something)
{
if(something)
}
or
if((something) &&(something))
关于java - 声纳显示方法可能无法清理已检查异常的流或资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33796679/