以下のうちどれが正しいか(それは重要ですか)。whileループで文を使用するJavaを作成
Connection conn = null;
conn = DriverManager.getConnection (url, userName, password);
Statement st = conn.createStatement();
while (a.b()) {
st.executeUpdate(blah blah); // same statement with different data values
}
st.close();
conn.close();
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (Exception e) { }
}
}
}
又は
Connection conn = null;
conn = DriverManager.getConnection (url, userName, password);
while (a.b()) {
Statement st = conn.createStatement();
st.executeUpdate(blah blah); //same statement with different data values
st.close();
}
conn.close();
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (Exception e) { }
}
}
}
「finally」ブロックで接続を閉じることをお勧めします。 – DNA
私はすでにそれを行っています。私のコードを更新しています。 – Ank