• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Closing Statement.

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am new to jdbc, closing a Statement is releasing its resources, I am wondering if this will include closing the connection itself.
also If I am connecting to localhost db,
Is creating a new Connection will be costy?
Is creating new Statement will be costy?

Thanks
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Costa,
Closing a statement will not close the connection because a connection is a higher level concept. Closing a connection will sometimes close a statement but you should not rely on this.

Creating a connection is usually relatively costly. This is why people use connection pools. Creating a statement is not costly and a frequent operation.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming that you're using a decent JDBC driver, closing a statement will only close any opened resultsets and closing a connection will close any opened statements and indirectly also its opened resultsets.

Obtaining a connection is the most expensive task in JDBC. You can improve performance by using connection pooling. When you're developing a webapplication, it's good to know that most self-respected application servers offers JNDI connection pooling out of the box. When you're developing a client application, then you may need to add connection pooling libraries so that you can make use of it. Commonly used ones are Apache Commons DBCP, C3P0 and Proxool
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic