Tomcat Configures SQLServer connection pool

xiaoxiao2021-03-06  13

Reference article:

Http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html

Configure Tomcat5.5.x connection pool

1. Enter the CONF folder directory under the Tomcat directory, find server.xml

In the tag and the tab in the tag, the format is as follows.

Debug = "5" reloadable = "true" crossContext = "true">

com.microsoft.jdbc.sqlserver.sqlserdriver .-->

JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = KB_Rate-->

Maxactive = "100" maxidle = "30" maxwait = "10000"

Username = "javauser" password = "javadude"

Driverclassname = "com.microsoft.jdbc.sqlserver.sqlserdriver"

URL = "JDBC: Microsoft: SQLServer: // localhost: 1433; DatabaseName = KB_RATE" "/>

After the configuration is complete, add a TEST file in the dbtest directory, as follows:

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

<% @ Page Import = "java.sql. *"%>

<% @ Page Import = "javax.sql. *"%>

<% @ Page Import = "javax.naming. *"%>

<%

Connection conn = NULL;

Context initctx = new initialContext (); if (initctX == null)

Throw New Exception ("You cannot get context!");

Context CTX = (Context) INitctX.lookup ("Java: Comp / ENV");

Object obj = (object) ctx.lookup ("/ default_jdbc"); // Get the connection pool object

Javax.sql.datasource DS = (javax.sql.datasource) OBJ; // Type conversion

CONN = ds.getConnection ();

Statement Stmt = conn.createstatement ();

PreparedStatement PS = conn.preparestatement ("Select * from firmOlRderData);

ResultSet RS = ps.executeQuery ();

While (rs.next ()) {

Out.println (rs.getstring (1) "
");

i ;

}

Rs.close ();

Stmt.close ();

CONN.CLOSE ();

Out.println ("Connection Pool Test Success" i);

It is also similar to the setting of Tomcat5.0 version, but there is nothing on the connection pool setting statement in Server.xml.

Http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples- ~howto.html

Other operations are also similar,

Debug = "5" reloadable = "true" crossContext = "true">

Debug = "5" reloadable = "true" crossContext = "true">

prefix = "localhost_dbtest_log." suffix = ". txt"

TimeStamp = "true" />

Auth = "container"

TYPE = "javax.sql.datasource" />

factory

org.apache.commons.dbcp.basicDataSourceFactory

Configure your mysqld max_connections large enough to handleall of your db connections. set to 0 for no limit.

->

maxactive

100

Set to -1 for no limit. See Also The DBCP Documentation on this

And The MinevictableIdletimeMillis Configuration Parameter.

->

maxidle

30

IN ms, in this example 10 seconds. An Exception Is Thrown IF

THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely.

->

maxwait

10000

Username

javauser

Password

javadude

If you want to use tris driver - We Recommend Using Connector / J Though

driverclassname

Org.gjt.mm.mysql.driver

->

driverclassname

com.mysql.jdbc.driver

The autoreconnect = true argument to the url makess supething

Connection. mysqld by Default Closes iDle Connections After 8 Hours.

->

URL

jdbc: mysql: // localhost: 3306 / javatest? AutoreConnect = true

There are indifferent places, please correct!

Also, it is to ask the prawn door to tell the younger brother, how to set up the method to make the connecting pool to the most efficient, because I tried to connect the pool of the pool with Tomcat, I found that the slower, longer, I don't know the wrong Where there,!! My setting is as follows:

Debug = "5" reloadable = "true" crossContext = "true">

Maxactive = "100" maxidle = "30" maxwait = "10000"

Username = "sa" password = "1234"

Driverclassname = "com.microsoft.jdbc.sqlserver.sqlserdriver"

URL = "JDBC: Microsoft: SQLServer: //127.0.0.1: 1433; DatabaseName = KB_RATE" />

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

New Post(0)