• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Connection Opening & Closing Every Time?

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, I have been writing using JDBC for a while connecting to my Oracle 9i database. I have always re-written the same block of code

and I was curious if I could do this just once in a program and run queries any time I want. This connection establishing and breaking is quite time taking (well, 3 seconds, but that's a lot) and I think that I should be able to do it less often. Since it seems to auto-commit after the connection is closed each time, I think I could just submit my own "commit" command to the database instead of closing the connection.
Would this require my entire program which accesses the database to be in the try section? What would happen if a query failed... would it kick out all of the things that had not been committed yet and go to the catch for the interrupt?
Any suggestions will be appreciated. The time it takes to establish a connection (3 seconds) is far too much since I access the database multiple times per screen. I realize that I will have to adjust my ResultSet accordingly.
Thanks!
~Jeff
 
Ranch Hand
Posts: 395
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff,
Use Connection Pool.
I think Oracle 9i provides option of Connection Pooling with Datasource also.
If not you may need to use the Connection Pool which is provided in the javax.sql package.
Cheers.
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lakshmeenarayana Goundalkar:
Hi Jeff,
Use Connection Pool.
I think Oracle 9i provides option of Connection Pooling with Datasource also.
If not you may need to use the Connection Pool which is provided in the javax.sql package.


Thanks for the fast response! Could you give me a brief example of this? I searched on Oracle's site, but found nothing much more than Oracle 9i does allow Connection Pooling. I searched Sun's site but found nothing different than what I am already doing. Further suggestions or example code would be greatly appreciated.
Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic