The use of Tomcat's JDBC Pooltomcat jdbc pool requires only 2 jar packages, Tomcat-jdbc.jar and Tomcat-juli.jar respectively, the two jar packages can be found in Tomcat7, Tomcat-jdbc.jar in the Tomcat directory, Tomcat-juli.jar in the bin directory. Http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/org.apache.tomcat.jdbc.pool Import Java.sql.Connection; Import Java.sql.ResultSet; Import java.sql.Statement; Import Org.apache.tomcat.jdbc.pool.DataSource; Import org.apache.tomcat.jdbc.pool.PoolProperties; public class Simplepojoexample {public static void main (string[] args) throws Exception {poolproperties P = new Poolproperties (); P.seturl ("Jdbc:mysql://localhost:3306/mysql"); P.setdriverclassname ("Com.mysql.jdbc.Driver"); P.setusername ("root"); P.setpassword ("password"); P.setjmxenabled (TRUE); P.settestwhileidle (FALSE); P.settestonborrow (TRUE); P.setvalidationquery ("SELECT 1"); P.settestonreturn (FALSE); P.setvalidationinterval (30000); P.settimebEtweenevictionrunsmillis (30000); P.setmaxactive (100); P.setinitialsize (10); P.setmaxwait (10000); P.setremoveabandonedtimeout (60); P.setminevictableidletimemillis (30000); P.setminidle (10); P.setlogabandoned (TRUE); P.setremoveabandoned (TRUE); P.setjdbcinterceptors ("org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;") + "Org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"); DataSource DataSource = new DataSource (); Datasource.setpoolproperties (P); Connection con = null; try {con = datasource.getconnection (); Statement st = Con.createstatement (); ResultSet rs = st.executequery ("SELECT * from user"); int cnt = 1; while (Rs.next ()) {System.out.println ((cnt++) +). Host: "+rs.getstring (" host ") +" User: "+rs.getstring (" user ") +" Password: "+rs.getstring (" PassworD ")); } rs.close (); St.close (); } finally {if (con!=null) try {con.close ();} catch (Exception ignore) {}}}}proxyconnectionproxyconnectionpooledconnection con = Idle.poll (); proxyconnection[pooledconnection[null]]00 xx 6c ..... S e l65 (2a), E C T. * . F r4f 4d 5f + 6f O M. T C _ c o64-D e. W H E R E20 4f 5f 49 44. C O D E _ I D3D 1 0 0 5 1 0 0 2 ' 27EscapeProcessorObject escapedsqlresult = Escapeproce Ssor.escapesql (SQL, SERVERSUPPORTSCONVERTFN (), Getmultihostsafeproxy ()); Escapetokenizer Escapetokenizer = new Escapetokenizer (SQL); [49, 48, 48, 53, 49, 48, 48, 50] [39, 49, 48, 48, 53, 49, 48, 48, 50, 39] [39, 49, 48, 48, 53, 49, 48, 48, 50, 39] [[39, 49, 48, 48, 53, 49, 48, 48, 50, 39]] Buffer sendpacket = Fillsendpacket (); Buffer sendpacket = This.connection.getIO (). Getsharedsendpacket ();Position = Mysqlio.header_length;this.results = Executeinternal (This.maxrows, Sendpacket, Createstreamingresultset () , True, Metadatafromcache, false); Buffer Getsharedsendpacket () {if (This.sharedsendpacket = = null) {This.sharedsendpacket = new Buffer (initial_p Acket_size); } return this.sharedsendpacket;} Protected Mysqlconnection checkclosed () throws SQLException {mysqlconnection c = this.connection; if (c = = null) {throw sqlerror.createsqlexception (messages.getstring ("statement.49"), sqlerror.sql_state_illegal_a Rgument, Getexceptioninterceptor ()); } return C;} Public Resultsetinternalmethods Execsql (Statementimpl callingstatement, String sql, int maxRows, Buffer packet, int resul Tsettype, int resultsetconcurrency, Boolean streamresults, String catalog, field[] Cachedmetadata, Boolean isBa TCH) throws SQLException return This.io.sqlQueryDirect (callingstatement, NULL, NULL, packet, maxRows, ResultsetType, resultSetConcurrency, Streamresults, catalog, cachedmetadata); Statementimplbuffer Resultpacket = SendCommand (Mysqldefs.query, NULL, Querypacket, FALSE, NULL, 0);
MySQL JDBC source analysis fragment and Tomcat's JDBC Pool