File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes DB connection on init Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "DB connection on init" Watch "DB connection on init" New topic
Author

DB connection on init

Inesh Hettiarachchi
Greenhorn

Joined: Feb 07, 2004
Posts: 25
hi
i want to know if i use connection pooling where should i establish my db connection is it in init or service
if i put in the init since the init is executed onely onece will give me any problems when concurrent uses login to the app or if i have 10 servlets will there any problem in the connection pool with 5 connection avalable.

it would be a big help if anyone can give me any thing
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You don't want to get your connection from the init method.
The point of a connection pool is to get a connection when you need it and return it to the pool as soon as your done with it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17243
    
    1

Personally, I'd avoid getting it from the pool anywhere in the Servlet code itself. You business logic and data access code should be in Plain Old Java Objects that are called from the Servlet. This way that business logic and data access can be reused by other types of clients.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Inesh Hettiarachchi
Greenhorn

Joined: Feb 07, 2004
Posts: 25
thanks a lot it did help me a lot
stan ioffe
Greenhorn

Joined: Jun 30, 2005
Posts: 16
Which app server are u using?
If you're using something like WebSphere, all you need to do is configure your JDBC connection and your connection pooling is going to be handled by the app server ... just a thought
-stan
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: DB connection on init
 
Similar Threads
Connection timeout issues
Best way of Connection Pooling
JDBC-Oracle
applet jdbc
Initializing dB connection in init section