次のコードサンプルがあります。
try {
conn = this.jdbcTemplate.getDataSource().getConnection();
stm = conn.prepareCall("{? =" + query + "}");
stm.registerOutParameter(1, OracleTypes.CURSOR);
if (params != null) {
for (int i = 0; i < params.length; i++)
stm.setString(i + 2, params[i]);
}
//getting result set from cursor
stm.execute();
res = (ResultSet) stm.getObject(1);
return DatabaseLayerUtils.getResultSetData(res);
} finally {
//closing cursor
if (res != null) res.close();
if (stm != null) stm.close();
if (conn != null) conn.close();
}
セクション内の要素の順序はfinally
重要ですか?
次のコードです:
if (res != null) res.close();
if (stm != null) stm.close();
に等しい:
if (stm != null) stm.close();
if (res != null) res.close();
か否か?
私の同僚が取り組んでいるプロジェクトには、次のような多くの構造があります。
if (stm != null) stm.close();
if (res != null) res.close();
これが正しい構文かどうか、または次のように修正する必要があるかどうかを理解する必要があります。
if (res != null) res.close();
if (stm != null) stm.close();
ありがとう。