【发布时间】:2012-02-25 00:48:56
【问题描述】:
以下哪项是正确的(或重要)。
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块中关闭连接... -
是的,我已经这样做了..我正在用它更新我的代码..