My Tomcat connection pool configuration process

zhaozj2021-02-12  137

1. Do not use Tomcat5 management page settings (no successful settings)

First add MSSQL driver in Tomcat5.0 / Common / LIB:

Msbase.jar, mssqlserver.jar, msutil.jar

2. Add: in Tomcat5 / Conf / Server.xml:

.......

.......

// below is added

factory org.apache.commons.dbcp.basicdataSourceFactory < Name> DriverclassName com.microsoft.jdbc.sqlser.sqlserverdriver URL jdbc: Microsoft: SQLServer: //127.0 .0.1: 1433; DatabaseName = MIDP username user password 1234567 maxactive 20 maxidle 10 maxwait -1

// Added content end

3. The contents of Tomcat5.0 / WebApps / pool / web-inf / web.xml are as follows:

Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"

"http://java.sun.com/dtd/web-app_2_3.dtd">

JDBC / SQLSERVERMIDP javax.sql.datasource Container

4.Tomcat5.0 / WebApps / pool / testpool.jsp code is as follows:

<% @ Page ContentType = "text / html; charset = GB2312"%>

<% @ page import = "java.sql. *"%> <% @ Page Import = "javax.sql. *"%> <% @ page import = "javax.naming. *"%> this is a tomcat datasource pool example

<% Try {datasource ds = null; initialcontext ctx = new initialcontext (); if (ctx == null) throw new exception ("no matching context environment"); DS = (DataSource) CTX.lookup ("Java: comp) / env / jdbc / sqlsermidp "); if (ds == null) throw new exception (" There is no matching database "); connection conn = ds.getConnection (); statement stmt = conn.createstatement (); string strsql =" Select * from person_info "; ResultSet RS = Stmt.executeQuery (strsql); while (rs.next ()) {Out.Println (rs.getstring (1));%>
<%} Out.println (" Database connection success !!! ");} catch (exception e) {Out.println (" Somthing Error! ");} Finally {if (rs! = Null) rclose (); if (stmt! = Null) Stmt.close (); if (CNNN! = null) cnn.close (); if (CTX! = null) ctx.close ();

%>

转载请注明原文地址:https://www.9cbs.com/read-6469.html

New Post(0)