Link to home
Start Free TrialLog in
Avatar of winsuncareer
winsuncareer

asked on

JDBC related question

If I use the same statement object and resultset object with more that one query like below
stmt = conn.prepareStatement(q1);
rs = stmt.executeQuery();
while(rs.next){
.....
.......
}
...
.....
.......//do I have to close the resultSet and the statement Objects before using them again.
stmt = conn.prepareStatement(q2)
rs=stmt.executeQuery()
.....
......
.......//close the same again in the same program?

My Question is if I want to use the same statement object and resultSet for more than one Query in the same program, do I have to close each time before using them again. If so, do I have to close the following each and every time in the program
1. ResultSet
2. Statement Object
3. Connection object
ASKER CERTIFIED SOLUTION
Avatar of hoomanv
hoomanv
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PreparedStatement can only execute the query it was created for (q1), so how do you want to use the same stmt for another query (q1) ?
errata --> another query (q2)