Hello Friends,
It is possible to Use two query with in single ResultSet
Hello Friends,
It is possible to Use two query with in single ResultSet
A result set corresponds to a single SQL query. However your "single" query could use UNION to effectively combine more than one query.
No you should not do this. For example
ResultSet rs = null;
Statement stmt1 = con.createStatement("Query1");
Statement stmt2 = con.createStatement("Query2");
rs = stmt1.executeQuery();
while(rs.next()){
}
//Here result set should be closed before assigning new result set to "rs" variable like
stmt1.close();
rs.close();
rs = stmt2.executeQuery();
You should close old result set before using it again. If you don't close the old resultset object then it will be in memory and never be garbage collected. If you close the DB connection object in this case(without closing resultset properly) then connection object is not garbage collected(not retuned to pool) as connection have reference(i.e. unclosed resultset).