Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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 ??
 
Siva Masilamani
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • 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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic