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 context> tag and the host> tab in the context> 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" "/> Context> 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" /> parameter>
Configure your mysqld max_connections large enough to handleall of your db connections. set to 0 for no limit. -> parameter>
Set to -1 for no limit. See Also The DBCP Documentation on this And The MinevictableIdletimeMillis Configuration Parameter. -> parameter>
IN ms, in this example 10 seconds. An Exception Is Thrown IF THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely. -> parameter> parameter> parameter>
If you want to use tris driver - We Recommend Using Connector / J Though parameter> -> parameter>
The autoreconnect = true argument to the url makess supething Connection. mysqld by Default Closes iDle Connections After 8 Hours. -> parameter> Resourceparams> Context> 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" /> Context>
");