Tomcat 5.5 connection pool Configuration

Source: Internet
Author: User
Take the PostgreSQL database as an example (the MySQL configuration is the same ). From runtime 5.5/common/lib
JDBC driver for PostgreSQL = http://jdbc.postgresql.org/download.html
MySQL JDBC driver = http://dev.mysql.com/downloads/connector/j/3.1.html
Then copy the corresponding JDBC Driver (JAR file) to tomcat5.5/common/lib to edit Tomcat 5.5/CONF/tomcat-users.xml, the configuration is as follows:
<Tomcat-users>
<Role rolename = "Tomcat"/>
<Role rolename = "role1"/>
<Role rolename = "manager"/>
<Role rolename = "admin"/>
<User Username = "Tomcat" Password = "Tomcat" roles = "tomcat, Manager, admin"/>
</Tomcat-users> edit Tomcat 5.5/CONF/server. XML
<Host name = "localhost" appbase = "webapps"
Unpackwars = "true" autodeploy = "true"
Xmlvalidation = "false" xmlnamespaceaware = "false"> Add the connection description
<Context Path = "/mytest" docbase = "mytest" DEBUG = "5" reloadable = "true" crosscontext = "true">
<Resource Name = "mytest_ds" auth = "Container"
Type = "javax. SQL. datasource" driverclassname = "org. PostgreSQL. Driver"
Url = "JDBC: PostgreSQL: // FIG: 5432/mytest_db"
Username = "s" Password = "" maxactive = "20" maxidle = "10" maxwait = "-1"/>
</Context>
Note:
Mytest is your war package name or the directory name you created in webapps/
Mytest_ds is the name of the connection data source.
Mytest_db is the database name. So far, the tomcat configuration is complete. Below are some JSP programs.
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<HTML>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> test of connection pool </title>
</Head>
<Body>
<%
Out. Print ("START <br/> ");
Try {
Initialcontext CTX = new initialcontext ();
Javax. SQL. datasource connectionpool = (javax. SQL. datasource) CTX. Lookup ("Java: COMP/ENV/mytest_ds ");
Connection conn = connectionpool. getconnection ();
Out. Print ("DB connection pool run OK! ");
Conn. Close ();
}
Catch (exception ex ){
Out. Print (ex. getmessage ());
Ex. printstacktrace ();
}
%>
</Body>
</Html> changed from: Guangdong Linux center Forum> Linux application area> Linux servers and Enterprise Applications> pang Jinsong, a question about Tomcat 5.5 connection pool Configuration

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.