Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
2.1.7
Hi everyone:
I get a connection from a hibernate session in my application,the code is the following :
Code:
Session session=HibernateUtil.currentSession();
Connection con=session.connection(); <----- Should I close it myself?
Statement stm=con.createStatement(); <----- Should I close it myself?
ResultSet rs=stm.executeQuery(hsql); <----- Should I close it myself?
close what???
I want to know after I use the resultSet ,Should I
close the connection or close Session? I mean that if I don't need have to
close jdbc connection and statement after I close Hibernate Session?
I don't know the following code which is right ?
1.
Code:
Session session=..... getSession();
Connection con=session.connection();
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery(hsql);
session.close(); <---------------Close Hibernate Session only ?
Or
2.
Code:
Session session=..... getSession();
Connection con=session.connection();
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery(hsql);
............do some jdbc work here ................
rs.close(); <----------close ResultSet myself?
stm.close(); <----------close Statement
con.close(); <----------close Connection
I want to know which is right in above two method? Thks!