Tomcat5 database connection pool configuration
This article mainly introduces this version of the TOMCAT5.0.25, the configuration of the database connection pool, and the JNDI lookup of the connection pool, and provides the corresponding test code. Finally, the common problems and solutions in the configuration and application process are pointed out.
1. Configuration Environment of this article: Tomcat5.0.25 JDK1.4 SQL Server 2000 Win2000
2. Configuration steps:
first step:
Start Tomcat, open IE Enter http: // localhost: 8080 / admin to enter Tomcat management interface in the address bar; click on the drop-down menu on the right side to select Create New Data Source in the lower right input box. Configuration information.
JNDI NAME: JDBC / XXX (XXX is the name yourself ")
Data Source URL: JDBC: Microsoft: SQLSERVER: // localhost: 1433; DatabaseName = Tempdb (connected data name)
JDBC Driver Class: com.microsoft.jdbc.sqlserver.sqlserverdriver
User name: User name to connect to the database
Password: Database password
Max. Active Connections: Maximum connection
Max. Idle Connections: is the maximum number of idle connections
Max. Wait for Connection: Maximum Waiting Connection
Step 2: Configure Web.xml Open Web.xml under WebApps / Root / Web-INF, add the following:
Step 3: Configure Tomcat (add classes)
First you want to download the installation of SQLSerVer-JDBC-driver, then put the three JAR files under its lib.
Under Tomcat / Common / LIB.
Precautions:
If we are a single JSP page we put it under Tomcat_Home / WebApps / root, but also need to modify the root.xml file under Tomcat_Home / Conf / Catalina / LocalHost /
To reference the configured JNDI data source. At the same time,
A: You can create a new xxx.xml file under Tomcat_Home / CONF / CATALINA / LOCALHOST, XXX is the name of the released web application, such as the web application I posted is jnditest, .xml file named jnditest.xml in this file plus:
XML Version = '1.0' encoding = 'UTF-8'?>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
Resourceparams>
Context>
Where E: / Tomcat 5.0 / WebApps / Jnditest is a directory for your publishing application, so you can test it.
Doing this is that every web application must create a file like JNDITEST.XML.
B; To avoid each web application to create a xxx.xml file, we can modify the server.xml file under Tomcat_Home / Conf, modify the following:
Join between
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
Resourceparams>
Context>
At the same time, the paragraph on the upper side: (can also be removed)
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
parameter>
Resourceparams>
Note To join in the web.xml file of each web application
3. test
Write a JSP file:
<% @ Page ContentType = "Text / HTML; Charset = GB2312"%> <% @ Page Import = "Java.sql. *"%>
<% @ Page Import = "javax.sql. *"%>
<% @ Page Import = "javax.naming. *"%>
<%
Context ctx = new initialContext ();
Connection conn = NULL;
CTX = New InitialContext ();
DataSource DS = (Datasource) CTX.lookup ("Java: Comp / Env / JDBC / TEST");
CONN = ds.getConnection ();
Statement Stmt = Conn.createStatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_Updata);
String SQL = "SELECT * from T_Student";
ResultSet RS = Stmt.executeQuery (SQL);
While (rs.next ()) {%>
<%
Out.print (Rs.getstring (1));
Out.print (Rs.getstring (2));
Out.print (Rs.getstring (3));
}%>
<%
Out.print ("Database Success, Congratulations on You");
Rs.close ();
Stmt.close ();
CONN.CLOSE ();
%>
body>
html>