• 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

Dat aBase connections should be kept inside servlets or Business Layer.

 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

while going through interview questions i came across this question .

Can a database connection pool be instantiated in init
method of servlet instead of server connection pool?
What will be the problem?


It is true that connection pool can be instantiated in init
method of Servlet and is available for the web application
to use, but generally there can be many web application
required to use database connection pool, and multiple
web applications do not have access beyond ServletContext.
So it is desirable to have external resources defined at
server level, not at an application level.


Please let me know what does rhe author mean by this ??
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lets say you have 5 application that needs to acces a particular database say MY_DB.

Now if you configure the connection pool for this database in the server then it is available for all the application that uses this connection pool else you have to individually initialize the connection pool for each and every application that uses the same database.

You know ServletConext is per application and generally you will duplicate the same logic in each and every application for instantiating the connection pool and hence it is better to define the external resources in the server level(Web/Application Server).
reply
    Bookmark Topic Watch Topic
  • New Topic