Tomcat 5.0.28 MySQL 5 connection pool creation)

Source: Internet
Author: User
Author Tag: Tomcat MySQL

Tomcat 5.0.28 MySQL 5 connection pool establishment reference http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html

1. Download the MySQL JDBC driver
Http://mysql.mirror.vmmatrix.net/Downloads/Connector-J/mysql-connector-java-3.1.13.tar.gz
Decompress the package and copy the JAR file to Tomcat Lib.

CD downloads
Tar xvzf mysql-connector-java-3.1.13
Sudo CP mysql-connector-java-3.1.13/opt/tomcat/common/lib

2. configure Server. xml

<Host name = "localhost" DEBUG = "0" appbase = "webapps"
Unpackwars = "true" autodeploy = "true"
Xmlvalidation = "false" xmlnamespaceaware = "false">

<! -- Configure the connection pool -->
<Context Path = "/zhaobiao" docbase = "/Media/workspace/J2EE/project/zhaobiao" DEBUG = "0" reloadable = "true">
<Resource Name = "JDBC/zhaobiao" auth = "Container" type = "javax. SQL. datasource"/>
<Resourceparams name = "JDBC/zhaobiao">
<Parameter>
<Name> factory </Name>
<Value> org. Apache. commons. DBCP. basicperformancefactory </value>
</Parameter>
<Parameter> <Name> maxactive </Name> <value> 10 </value> </parameter>
<Parameter> <Name> maxidle </Name> <value> 30 </value> </parameter>
<Parameter> <Name> maxwait </Name> <value> 5000 </value> </parameter>
<Parameter> <Name> username </Name> <value> chenzhixin </value> </parameter>
<Parameter> <Name> password </Name> <value> 19851026 </value> </parameter>
<Parameter> <Name> driverclassname </Name> <value> com. MySQL. JDBC. Driver </value> </parameter>
<Parameter>
<Name> URL </Name>
<Value> JDBC: mysql: // localhost: 3306/zhaobiao? Autoreconnect = true </value>
</Parameter>
</Resourceparams>
</Context>

Zhaobiao in <Resource Name = "JDBC/zhaobiao" is my database name

3. Configure web. XML in your working directory

Before </Web-app>, add
<Resource-ref>
<Description> connection pools </description>
<Res-ref-Name> JDBC/zhaobiao </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>

4. Test

<HTML>
<% @ Page import = "javax. SQL. *, java. SQL. *, javax. Naming. *" %>
<Body>
<%
Try {
Context CTX = new initialcontext ();
Context envctx = (context) CTX. Lookup ("Java: COMP/ENV ");
Datasource DS = (datasource) envctx. Lookup ("JDBC/zhaobiao ");

Connection conn = Ds. getconnection ();
Statement ST = conn. createstatement ();
Resultset rs1_st.exe cutequery ("select * From maker ");

While (Rs. Next () {out. println (Rs. getstring (2 ));}
} Catch (exception e) {out. println (E );}
%>
</Body>
</Html>

5. Restart Tomcat and enter http: // localhost/zhaobiao/connectionpools. jsp.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 938014

Related Article

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.