Tomcat 5.5 connection pool Configuration
Last Update:2018-12-04
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