the object stmtInstance got a issue “Use try-with-resources or close this “PreparedStatement” in a “finally” clause.”
why?
public void getData(String extractSql, Connection conn) {
try {
PreparedStatement stmtInstance = null;
ResultSet resultSet = null;
try {
stmtInstance = conn.prepareStatement(extractSql); //got issue "Use try-with-resources or close this "PreparedStatement" in a "finally" clause."
resultSet = stmtInstance.executeQuery();
} catch (Exception e) {
log.error("sql error:" + e.getMessage());
} finally {
try {
if (stmtInstance != null) {
stmtInstance.close();
}
} catch (Exception e) {
log.error("ERROR:[{}]", e.getLocalizedMessage());
}
try {
if (resultSet != null) {
resultSet.close();
}
} catch (SQLException e) {
log.error("ERROR:[{}]", e.getLocalizedMessage());
}
}
} catch (Exception e) {
log.error("ERROR:[{}]", e);
}
}