Tomcat and JDBC connection pooling

B

Baba

Hi everybody.

I have learned JDBC and mostly everything I need for the usual database-java
communication, but I was wandering something about the subject of connection
pooling.

I know how to make a servlet that does the pooling for me, but I presume
there is an easier way to achieve it through the Tomcat administration tool.
Unfortunately I do not know how to set that up and use it.

Can anybody give me some help on that subject or point me to an useful link?
thanks.
 
A

Alan

Well, I don't know if this can be set up using the console, but the
documentation for Tomcat 5 DB pooling can be found at:

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html

Here are the Tomcat 4 docs:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

The administration console can be found at (under default install):
http:localhost:8080/admin

But, you have to set up a user and password in your
<tomcat-install>/conf/tomcat-users.xml file.

You need to add an "admin" role and a user that will be assigned this
role like this (obviously you won't be using "tomcat" as your password):

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="admin"/>
</tomcat-users>

So, I can log in as Tomcat and have admin privs.

This file is a Tomcat 4.1.24 user file... I think they are still the
same... Check out:

Tomcat 5
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/manager-howto.html

Tomcat 4
http://jakarta.apache.org/tomcat/to...o.html#Configuring Manager Application Access

Hope this helps!

<briggs />
 
K

KD

OK first go to the Tomcat administration tool (See the reply from Alan
below)
..
Click on the mini magnifying glass type of icon to navigate the tree
structure.

Navigate as follows:
Service --> Host (localhost) --> Context (/your_webapp_name) --> Resources

Now click on the data sources link in the tree. In the main frame
window, select the "create new data source" from the drop down that is
labelled "Data Source Actions".

Fill in your normal JDBC stuff. Importantly fill in the following for
the "JNDI Name:" jdbc/abc_def

Click on the Commit Changes button (top right) to save your changes.

Now this is how you would access your data from a servlet or any other
class.

// Obtain our environment naming context
InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");

// Get a datasource
Datasource myDS = (DataSource)envCtx.lookup("jdbc/abc_def);

From the datasource you get a Connection object and off you go. Your
connections are pooled thanks to Tomcat and its use of the Apache
Commons DBCP project.

Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top