Tomcat and JDBC connection pooling

Discussion in 'Java' started by Baba, Feb 16, 2004.

  1. Baba

    Baba Guest

    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.
     
    Baba, Feb 16, 2004
    #1
    1. Advertising

  2. I'm sure that a little googling, seaching this newsgroup and the tomcat
    docs would have given you this url:
    http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html

    enjoy!

    Baba wrote:

    > 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.
    >
    >
     
    David Rabinowitz, Feb 17, 2004
    #2
    1. Advertising

  3. Baba

    Alan Guest

    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 />


    Baba wrote:

    > 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.
     
    Alan, Feb 20, 2004
    #3
  4. Baba

    KD Guest

    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!







    Alan wrote:

    > 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 />
    >
    >
    > Baba wrote:
    >
    >> 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.
     
    KD, Feb 23, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chandrakanth

    Tomcat Connection pooling with oracle

    Chandrakanth, Jun 7, 2004, in forum: Java
    Replies:
    0
    Views:
    471
    Chandrakanth
    Jun 7, 2004
  2. bigbinc
    Replies:
    0
    Views:
    542
    bigbinc
    Jul 23, 2004
  3. Aquila Deus
    Replies:
    3
    Views:
    978
    anonymous
    Feb 1, 2005
  4. Replies:
    1
    Views:
    375
    Marc E
    May 23, 2006
  5. Alex Collins

    JDBC Connection Pooling and Fail-over

    Alex Collins, Oct 21, 2009, in forum: Java
    Replies:
    7
    Views:
    2,169
    Tom Anderson
    Oct 30, 2009
Loading...

Share This Page