Tomcat connection pool first configuration successful state

zhaozj2021-02-16  60

surroundings:

JDK1.4 Tomcat 5

I. Environment variable:

PATH: C: /J2SDK1.4.2/bin;

Java_Home: C: /J2SDK1.4.2/

Note: Only two.

two. SQL Server driver

Copy

Microsoft SQL Server 2000 Driver For JDBC / LIB / Directory three .jar:

Msbase.jar

MSSQLServer.jar

Msutil.jar

TO

Tomcat5 / Common / LIB

Third. Virtual directory and connection pool

Suppose you want to build your own virtual directory in D: / jsgtest

/ myjsp

Suppose you want to connect the pool JNDI named AAA

Assume that the connection database is PUBS

Be

Tomcat5 / Conf / Catalina / Localhost

New file under the directory:

Myjsp.xml

The content is as follows:

< Resource name = "aaa" type = "javax.sql.datasource" />

URL JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = Pubs

Password Kingapex

maxactive 4

maxWait 5000 driverclassname com.microsoft.jdbc.sqlserver.sqlserverdriver Username sa maxidle 2

test:

Built in the D: / jsgtest directory: test.jsp: <% @ page contenttype = "text / html; charset = GB2312"%> <% @ page import = "java.sql. *"%> <% @ Page Import = "javax.sql. *"%> <% @ Page Import = "javax.naming. *"%> <% connection conn = null; context itis = new initialContext (); if (initctx == null) throw new new new Exception ("Can't get context!"); Context CTX = (Context) INitctX.lookup ("Java: Comp / ENV"); // Get the connection pool object Object obj = (Object) CTX.lookup ("aaa"); // Type conversion javax.sql.datasource DS = (javax.sql.datasource) obj; conn = ds.getConnection ();

STATEMENT Stmt = Conn.createStatement (); string strsql = "select * from [titles]"; ResultSet RS = stmt.executeQuery (strsql); while (rs.next ()) {Out.println (rs.getstring (1) );

}

Rs.close (); stmt.close (); conn.close ();

Out.println ("Successful connection pool test");%>

Test path:

Http: // localhost: 8080 / myjsp / test.jsp

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

New Post(0)