Hi,
I want to know that if a PreparedStatement object is initialized twice the way shown in code snippet below and closed only once in finally block, will it fail to close? I am not getting any error in this code but will it be a better idea to use 2 different preparedStatements instead of one. I think it fails to close the preparedStatement at #1.
Connection conn = null;
PreparedStatement ps = null;
try {
conn = getConnection();
ps = conn.prepareStatement(QueryUtil.UPDATE_POLICY_DETAILS); // #1
ps.setInt(1, iCancellationPolicyId);
ps.executeUpdate();
//some code here
ps = conn.prepareStatement(QueryUtil.UPDATE_POLICY_CHARGES); // #2
ps.setInt(1, iCancellationPolicyId);
ps.executeUpdate();
//some code here
} catch (SQLException sqlExp) {
sqlExp.printStackTrace();
LOG.fatal(sqlExp);
} finally {
ps.close();
conn.close();
}