Proxool Introduction
The Proxool connection pool is an open source project under SourceForge that provides a robust and easy-to-use connection pool, the most critical of which is the ability to monitor the connection pool, which is easy to use and facilitates the discovery of connection leaks. Open Source project address is: http://proxool.sourceforge.net/
Proxool provides a number of configuration properties with the following attributes, and of course it is recommended to view the official document Http://proxool.sourceforge.net/properties.html directly:
1. Configure Proxool.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<something-else-entirely>
<proxool>
<alias>dbname</alias> < aliases!--data sources--
<!--database connection information --
<driver-url>jdbc:mysql://localhost:3306/zz</driver-url>
<driver-class>com.mysql.jdbc.driver </driver-class>
<driver-properties>
<property name= "user" value= "root"/>
<property name= "password" value= "123123"/>
<property name= "Useunicode" value= "true"/> <!--using Unicode character encoding set --
<property name= "characterencoding" value= "Utf-8"/> <!--character coded to Utf-8
</driver-properties>
<!--maximum number of connections--
< minimum number of connections!----
<minimum-connection-count>10</minimum-connection-count>
<!--minimum Increment--
<simultaneous-build-throttle>10</simultaneous-build-throttle>
<prototype-count>5</prototype-count>
<!--detect before use
<test-before-use>true</test-before-use>
<!--This is the syntax for MySQL, different databases--
<!--This is how Oracle is written, Each database has a difference --
</proxool>
</something-else-entirely>
2. Configure Web. XML
<servlet><servlet-name>ServletConfigurator</servlet-name><servlet-class> Org.logicalcobwebs.proxool.configuration.servletconfigurator</servlet-class><init-param> < param-name>xmlfile</param-name> <param-value>WEB-INF/proxool.xml</param-value> <!--proxool.xml configuration file Location--</init-param> <load-on-startup>1</load-on-startup > </servlet>
3. Get the connection
1 Importjava.sql.Connection;2 ImportJava.sql.DriverManager;3 Importjava.sql.PreparedStatement;4 ImportJava.sql.ResultSet;5 Importjava.sql.SQLException;6 7 /**8 * @authorCTD9 *Ten */ One Public classDbutils { A - Private StaticDbutils me=Newdbutils (); - the Privatedbutils () {} - - Public Staticdbutils getinstance () - { + returnme; - } + A /** at * Get database connection - * @return - */ - PublicConnection getconn () - { - inConnection conn=NULL; - to Try { + //See if this driver entry class exists in the Classpath -Class.forName ("Org.logicalcobwebs.proxool.ProxoolDriver"); theConn=drivermanager.getconnection ("Proxool.dbname"); //proxool. Database aliases * $}Catch(ClassNotFoundException e) {Panax Notoginseng //TODO auto-generated Catch block - e.printstacktrace (); the}Catch(SQLException e) { + //TODO auto-generated Catch block A e.printstacktrace (); the } + - returnConn; $ $ } - - /** the * Release Database Resources - * @paramConnWuyi * @parampstmt the * @paramRSet - */ Wu Public voidreleaseres (Connection conn,preparedstatement pstmt,resultset rset) - { About Try{ $ if(rset!=NULL) Rset.close (); - if(pstmt!=NULL) Pstmt.close (); - if(conn!=NULL) Conn.close (); -}Catch(SQLException e) A { + e.printstacktrace (); the } - } the}
Use of Proxool + MySQL + servelt