在JDBC中,可以使用单个Statement
对象多次调用executeQuery("")
吗?安全吗?或者,我应该在每次查询后关闭statement对象,然后创建新对象来执行另一个查询。
例如:
Connection con;
Statement s;
ResultSet rs;
ResultSet rs2;
try
{
con = getConnection();
s = con.prepareStatement();
try
{
rs = s.executeQuery(".......................");
// process the result set rs
}
finally
{
close(rs);
}
// I know what to do to rs here
// But I am asking, should I close the Statement s here? Or can I use it again for the next query?
try
{
rs2 = s.executeQuery(".......................");
// process the result set rs2
}
finally
{
close(rs2);
}
}
finally
{
close(s);
close(con);
}
https://stackoverflow.com/questions/21327012
复制相似问题