• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When to close Statement & ResultSet?

 
Stefan Elfvinge
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo, is it a general solution to always close
the Statement- and ResultSetobjects after you get what you want(executing the statement and iterating through the resultset)? What would happen if I "fail" to close either of them?
In my webapp I execute a number of statements and I just discovered I never close them or the resultsets. BUT, it works fine testing it(only one user), would problems appear when several users are involved?
Should the connectionobject be closed as well after executing just ONE statement, or how to decide when to close the connection?
Thanks
 
Vels Manian
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The resultset is automatically closed if u execute the execute() in Statement or if u close the statement and statement is closed when it is garbage collected. But its a good programming practice to close these objects after use.
Cheers,
vels
 
Stefan Elfvinge
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
but what about the Connectionobject???
When to dispose of db-connection?
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can close the Db connection whneever you are finished with it. Since your other objects, such as, statement, Resultset, etc. depend on the DB connection, clossing the DB connection will automatically release thos objects too.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic