JSP + mysqll + tomcat6.0 database connection pool Configuration

Source: Internet
Author: User

Put the MySQL driver package in my: e:/tomcat 6.0/lib and the corresponding project WEB-INF/lib folder.

1. Modify CONF/server. xml and add the following content (some parameters ):

<Context Path = "/Web" docbase = "Web" DEBUG = "0" reloadable = "true" crosscontext = "true">
<Resource Name = "JDBC/query" auth = "Container" type = "javax. SQL. datasource" driverclassname = "com. MySQL. JDBC. Driver"
Url = "JDBC: mysql: // localhost: 3306/databasename"
Username = "XX" Password = "XX"

Maxidle = "10" maxwait = "500" maxactive = "200" removeabandoned = "true" removeabandonedtimeout = "60" logabandoned = "true"/>
</Context>

2. Modify the Web. xml of the corresponding application and add the following content before </Web-app>:

<Resourcelink name = "JDBC/query" Global = "JDBC/query" type = "javax. SQL. Cer CER"/>

Restart tomcat. OK!

Test the connection retrieval function as follows:

<% @ Page contenttype = "text/html; charset = UTF-8" %>
<% @ Page import = "javax. Naming. Context" %>
<% @ Page import = "javax. SQL. datasource" %>
<% @ Page import = "javax. Naming. initialcontext" %>
<% @ Page import = "Java. SQL. *" %>
<HTML>
<Body>
123
<%
Datasource DS = NULL;
Try {
Context initctx = new initialcontext ();
Context envctx = (context) initctx. Lookup ("Java: COMP/ENV ");
// Lookup data source from context.
DS = (datasource) envctx. Lookup ("JDBC/query ");
If (Ds! = NULL)
{
Out. println ("datasource obtained! ");
Out. println ("<br> ");
Connection conn = Ds. getconnection ();
Statement stmt = conn. createstatement ();
Resultset rst1_stmt.exe cutequery ("select * from table"); // read data from a table
Out. println ("the following data is read from the database: <br> ");
While (RST. Next ()){
Out. println ("<br> ");
Out. println (RST. getstring (8 ));}

}
}
Catch (exception ne)
{
Out. println ("exception: <br> ");
Out. println (NE );
}

%>
</Body>
</Html>

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.