Section 01 Why need the connection tooling when we entered the development of Java, Pool is also a learning, how to make the connection to the DB link, and later people can use the connection already Pool, reduce the time, so Excellent features have been implemented in many Application Server, you only need to simply follow the instruction file configuration, including the maximum connection number, the initial link number, the maximum number of waiting quantities, etc., of course, Tomcat also has built COMMONS-DBCP Connection pooling mechanism, please check Tomcat JNDI Datasource setting !! And Proxol is a powerful connection poibility project, compatible with JDK 1.3 and 1.4. Monitor, record, etc. And paying attention to Performation project, it is a very complete solution. Download area, current version 0.7.2http: //sourceforge.net/projects/proxool/ section 02 Setting Administlet first, you have to download the proxool LIB below All JAR files are placed under WEB-INF / LIB, in addition, put your JDBC Driver is also the same LIB, then configure /Web-inf/web.xml
Web.xml
XML Version = "1.0" encoding = "UTF-8"?>
Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"
"/Web-inf/dtds/web-app_2_3.dtd">
servlet>
servlet-maping>
web-app>
Section 03 Creating a JSP or Dao Bean through Proxoldriver, establishing a Connection through org.logicalcobwebs.proxool.proxoldriver
Test.jsp
<% @ Page Import = "java.sql. *"%>
<%
Connection connection = NULL;
Try {
Class.Forname ("Org.LogicalCobwebs.Proxool.ProxoOLDRIVER");
Connection = DriverManager.getConnection
"Proxool.test: org.gjt.mm.mysql.driver: jdbc: mysql: // localhost: 3306 / test",
"root",
"Password"
);
} catch (exception e) {
Out.println (e)
}
Out.println ("OK");
%>
Section 04 Viewing Pooling Today Perform http: // localhost: 8080 / proxool-test / admin (Proxool-Test is your app name) If there is no Pool state, you will only see the words of Pools, so You will perform http: // localhost: 8080 / proxol-test / test.jsp to create a connection, you can monitor the status of Connection Pooling.
Pools
> TEST -> JDBC: MySQL: // WWW: 3306 / Testdefintition for test
URLjdbc: mysql: // localhost: 3306 / testDriverorg.gjt.mm.mysql.DriverConnections0 (min), 15 (max) PrototypingoffConnection Lifetime11: 00: 00Maximum active time07: 05: 00House keeping sleep time30sHouse keeping test SQLoffFatal SQL exceptionsoffStatisticsoffSnapshot at 21: 12:53
Start Date01 - ?? - 2003 21: 12: 30connections1 (Active), 0 (Available), 15 (MAX)
Served1Refused0Details
#bornlaststartlap (ms) thread1 21:12:31 21: 12: 3122432 Thread-15less Information
Proxool 0.7.2 (29-APR-2003 00:33)
Section 05 Use Properties or XML to set the DB URL and Driver to use XML configuration files, using jaxpconfigurator.configure ("proxool.xml", false) in the program; configuration file settings are as follows
WEB-INF / Proxool.xml
Xml Version = "1.0" encoding = "ISO-8859-1"?>
ANYTHING OUTSIDE The "Proxool" tag is ignored. ->
driver-property>
proxool>
Something-Else-Entirely>
You can also use Properties, in program printyconfigurator.configure ("proxool.properties"; file settings
WEB-INF / Proxool.properties
JDBC-0.Proxool.Alias = Property-Test
JDBC-0.Proxool.driver-url = jdbc: mysql: // localhost: 3306 / TEST
JDBC-0.Proxool.driver-class = org.gjt.mm.mysql.driver
JDBC-0.User = root
JDBC-0.Password = Password
JDBC-0.Proxool.Maximum-connection-count = 10
JDBC-0.Proxool.House-Keeping-Test-SQL = SELECT CURRENT_DATE
If you use it in web, you can also set the servletconfigurator servlet to register in Web.xml.
XML Version = "1.0" encoding = "UTF-8"?>
Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"
"/Web-inf/dtds/web-app_2_3.dtd">
Org.LogicalCobwebs.Proxool.configuration.ServletConfigurator
servlet-class>
init-param>
servlet>
Org.LogicalCobwebs.Proxool.admin.Servlet.AdminServlet
servlet-class>
servlet>
servlet-maping>
web-app>
In the program, you only need to use the alias to call the Connection Pool to use <% @ Page Import = "java.sql. *;"%>
<%
Connection connection = NULL;
Try {
Class.Forname ("Org.LogicalCobwebs.Proxool.ProxoOLDRIVER");
Connection = DriverManager.getConnection ("proxool.xml-test");
} catch (exception e) {
Out.println (e);
}
Out.println ("OK");
%>
Section 06 Using Connection.Close () Close Connection Orders, I have not written close, I hope everyone remember to use Close () to shut down after the connection is finished, to avoid java.sql.sqlexception: ORG. LogicalCobwebs.Proxool.Proxoolexception: ConnectionCount IS 10. Maximum Connection Count of 10 Cannot Be Exceeded.
Reference - related books or related articles
Proxool: http://proxool.sourceforge.net/ Proxool API: http://proxool.sourceforge.net/api-dev/index.html
News - OpenSource News
2003/07/30 - Poi 2.0-pre3 Released 2003/08/01 - Tomcat 4.1.27 Stable Released 2003/08/01 - Commons HttpClient 2.0 Release Candidate 1 Released