Tomcat data source configuration (Database Connection Pool configuration process)

Source: Internet
Author: User

If you are using myeclipse, it is very simple and only takes three steps.
First, find the context. xml configuration file in the directory where you install Tomcat. The path is [D: \ Program Files \ apachesoftware Foundation \ Tomcat 6.0 \ conf \ context. xml]
Modify the file and add the following

<Resource    name="jdbc/mldn"    auth="Container"    type="javax.sql.DataSource"    maxActive="100"    maxIdle="30"    maxWait="10000"    username="root"    password="690811"    driverClassName="org.gjt.mm.mysql.Driver"    url="jdbc:mysql://localhost:3306/mldn"/>

Attribute description:
Name, data source name, usually in the format of "JDBC/XXX;
Type, "javax. SQL. datasource ";
Password: the password of the database user;
Driveclassname, database driver; (commonly used, MySQL is "com. mySQL. JDBC. driver "; oracle is" Oracle. JDBC. driver. oracledriver "; ms SQL is" ")
Maxidle, maximum number of idle instances, and maximum idle time for database connection. When the idle time is exceeded, the database connection is marked as unavailable and then released. If it is set to 0, there is no limit.
Maxactive: the maximum number of database connections in the connection pool. If it is set to 0, there is no limit.
Maxwait, maximum connection wait time. If this time is exceeded, an exception occurs. If it is set to-1, there is no limit.

2. Configure the Web. xml file under the project

    <resource-ref>        <description>DBConnection</description>       <res-ref-name>jdbc/mldn</res-ref-name>       <res-type>javax.sql.DataSource</res-type>       <res-auth>Container</res-auth>    </resource-ref>

Third: place the Third-Party driver connecting to the database under [my path is D: \ ProgramFiles \ Apache Software Foundation \ Tomcat 6.0 \ Lib ].
So far OK.

However, after my detection, I found that for the first step, if you do not use myeclipse, you can configure the project path by yourself.
Find the server. xml file. My path is [D: \ Program Files \ apache softwarefoundation \ Tomcat 6.0 \ conf \ Server. xml]

Modify the file as follows:

<Context path="/mars"docBase="E:\Workspace_myeclipse\DemoMLDN"reloadable="true">    <Resource        name="jdbc/mldn"        auth="Container"        type="javax.sql.DataSource"        maxActive="100"        maxIdle="30"        maxWait="10000"        username="root"        password="690811"       driverClassName="org.gjt.mm.mysql.Driver"       url="jdbc:mysql://localhost:3306/mldn"/></Context>

The modification here means that knowledge is only for the connection pool configured for a web project.
This configuration method is not only cumbersome but also prone to configuration errors. We recommend that you do not use this method.

Then, let us know the test procedure.
The test procedure is as follows: a simple JSP file

<% @ Page import = "Java. SQL. connection "%> <% @ page import =" javax. SQL. datasource "%> <% @ page import =" javax. naming. initialcontext "%> <% @ page import =" javax. naming. context "%> <% @ page contenttype =" text/html "pageencoding =" GBK "%> <HTML> 

The running result is:

JDBC: mysql: // localhost: 3306/mldn, username = root @ localhost, MySQL-AB JDBC driver

This can also be done for Oracle. There are many examples on the Internet. You can find them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.