• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Connection

 
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Where should we get JDBC connnection, init() method or service method?

To my knowledge it should be in init method colse in destroy.

But if some exception or rather error because of which init method doesnt get successfully executed and load-on-startup for servlet is 1, will server crash?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on what you are going to do with that connection.

High performance / high load applications don't establish their connections in a servlet at all. They use connection pools which allow your servlet to access an already running connection when it needs it.

If you create your connection in the init method, all requests will have to share the same connection. You will have to insure that there are no concurrency issues if several requests try to access that connection at the same time.

If you establish your connection in one of the service methods, each hit will have to wait while the (usually expensive) connection is made.


You can find a quick explanation of connection pools here.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,
thanks alot for reply.

I understood what you said.

I just wanted to know if some error occurs during the init method, or unhandled exception, and load-on-startup is 1 for that servlet, will application server crash?

Kind Regards

Rajesh
 
reply
    Bookmark Topic Watch Topic
  • New Topic