Connection Pool (implemented by proxool)

Source: Internet
Author: User
Tags netbeans

1. Create the proxool. xml file under the WEB-INF directory in the project (also in other directories, as long as you can find it) with the content:

 

<? XML version = "1.0" encoding = "UTF-8"?> <Proxool> <! -- Database connection alias, which is obtained through proxool.15dayweb --> <alias> 15 dayweb </alias> <! -- Database driver --> <driver-URL> JDBC: mysql: // localhost: 3306/15 dayweb </driver-URL> <! -- Driver Class --> <driver-class> com. MySQL. JDBC. Driver </driver-class> <! -- Online database user and password --> <driver-Properties> <property name = "user" value = "root"/> <property name = "password" value = "root" /> </driver-Properties> <! -- Minimum number of connections. We recommend that you set a value greater than 0 to ensure the first connection time --> <Minimum-connection-count> 2 </minimum-connection-count> <! -- Maximum number of connections. If the maximum number of connections is exceeded, an excessive number of connections will be thrown, the server CPU and memory consumption is very high --> <maximum-connection-count> 20 </maximum-connection-count> <! -- Maximum number of connections at a time point --> <simultaneous-Build-Throttle> 10 </simultaneous-Build-Throttle> <! -- Number of connections generated at a time --> <prototype-count> 2 </prototype-count> <! -- The default value of the maximum connection time is 5 minutes. Unit: seconds --> <maximum-active-time> 120 </maximum-active-time> <! -- The maximum connection life time is 4 hours by default. Unit: seconds --> <maximum-connection-lifetime> 600 </maximum-connection-lifetime> </proxool>

 

2. Add the configured data source to Web. XML in the project, and add the following content under Web-app:

<! -- Configure the data source --> <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> </init-param> <load-on-startup> 1 </load-on-startup> </servlet> <! -- The management and monitoring tool provided by proxool to view the current database connection status. --> <Servlet-Name> admin </servlet-Name> <servlet-class> Org. logicalcobwebs. proxool. admin. servlet. adminservlet </servlet-class> </servlet> <servlet-mapping> <servlet-Name> admin </servlet-Name> <URL-pattern>/admin </url-Pattern> </servlet-mapping>

 

If you do not use the management and monitoring tool, you do not need to configure it.

 

3. test:

// Obtain the public void getconnection () throws exception {If (conn = NULL) {// class of the proxool driver. forname ("org. logicalcobwebs. proxool. proxooldriver "); // The dbpool here is in proxool. the connection pool alias conn = drivermanager configured in XML. getconnection ("proxool.15dayweb") ;}// database access, perform the query Operation Public resultset query (string SQL) throws exception {// initialize the database connection getconnection (); // create the statement object statement stmt = Conn. createstatement (); // construct an SQL statement SQL = "select * From about_team_table"; return stmt.exe cutequery (SQL );} // test whether the data in the about_team_table table can be read normally. Public static void main (string [] ARGs) throws exception {dbdao dd = new dbdao (); resultset rs = DD. query (""); While (RS. next () {system. out. println (RS. getint ("ID"); system. out. println (RS. getstring ("name"); system. out. println (RS. getstring (3); system. out. println (RS. getstring (4); system. out. println (RS. getbinarystream ("photo "));}}

 

 

Appendix:

Http://proxool.sourceforge.net/index.html

The connection is not automatically closed during the test. When the active connection time is exceeded in the monitoring tool, the connection must be released, after all, the maximum number of connections is limited.

Tomcat: APACHE-Tomcat-6.0.18

JDK: jdk-6u11-windows-i586-p

Netbeans version: netbeans-6.5-ml-windows

Proxool version: proxool-0.9.1

 

Hibernate supports third-party connection pools. the officially recommended connection pools are c3p0, proxool, and DBCP.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.