고정 코드 분석기로 코드를 스캔했으며 개봉되지 않은 리소스 : 데이터베이스 오류가 발생했습니다. 나는 아래의 모든 DB 연결을 닫고 내 코드의 스냅 샷입니다.정적 코드 분석 설명
public String methodInDAO(Bean bean) throws SQLException ,Exception
{
Session session = null;
Connection connection = null;
ResultSet resultSet1 = null;
CallableStatement callableStatement = null;
try {
connection = dataSource.getConnection();
callableStatement = connection.prepareCall(query);
resultSet1 = callableStatement.execute();
//code operations
} finally {
if(null != callableStatement)
callableStatement.close();
resultSet1 = null;
callableStatement = null;
if(null != connection)
connection.close();
if (null != session)
session.close();
}
return returnOutput;
}
모든 예외는 서비스 계층에서 처리됩니다. 아무도 데이터 소스가 공개되지 않는다고 제안 할 수 있습니까?
'connection.close()'가 예외를 throw하면 어떻게 될까요? 연결이 아직 열리거나 닫혀 있습니까? – Tom
'resultSet1 = null; '이 결과 집합을 닫지 않습니다. callableStatement를 닫기 전에'resultSet1.close()'를해야한다. [ResultSet.close] (http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#close())가 SQLException을 던지고 있으므로 try {} catch()를 사용해야합니다. 리소스를 닫을 때 차단되므로 초기 예외가 무시되지 않습니다. – Daniel
throw 된 모든 예외는 서비스 계층에서 처리되므로 finally 블록에 throw 된 예외도 동일한 레이어에 포함됩니다. – jain626