I. Configuration of Tomcat4's connection pool under Win2k 1. Install JDK1.4 and Jakarta-Tomcat-4.1.27.exe. The paths are D: /JDK1.4 and D: / Tomcat 4.1, respectively. When you install Tomcat 4, you will be required to fill in the web access port, user name, password, etc. Web Access Port Minimal thinks 8080, username is Default as admin, password yourself. Start Tomcat4, access http://127.0.0.1:8080/, you can see the welcome access page of Apache Tomcat / 4.1.27, some related introduction information, etc. on the page. 2. Setting the Database to the Oracle's JDBC Driver Set to: Oracle8i's driver is in / oracle / ORA81 / JDBC / LIB / directory. The name is classes12.zip. Oracle9i driver In / Oracle9i / JDBC / LIB / Directory, the name is ojdbc14.jar. Copy this file under D: / Tomcat 4.1 / Common / LIB. Note that if you use Oracle8i driver, you need to rename the class 12.zip to class 12.jar in the D: / Tomcat 4.1 / Common / Lib directory, because Tomcat4 does not know the Zip's suffix name. 3. Set the web application. Create a new folder, the name is MyPool, the location is d: / mypool. This d: / mypool path will be the main directory of the web application. Open the D: / Tomcat 4.1 / conf / server.xml file, find the following line: -> In this, add the following:
Then click on the "Data Sources" item on the left side, and the page of the JNDI configuration can be seen on the right. In the drop-down box in the upper right corner, select "Create New Data Source", follow the configuration information: JNDI Name: JDBC / MyorCl Data Source URL: JDBC: Oracle: Thin: @ 192.168.6.40: 1521: DBServer JDBC Driver Class: Oracle .jdbc.driver.racledriver user name: MyName Password: mypassword max. Active Connections: Available default max. Idle Connections: Available Default max. Wait for Connection: Available default values Validation Query: Do not fill in. Then, press the "SAVE" button to save. Then press the "Commit" button to complete the configuration change. If you look at the Tomcat4 window, you will find that there is a line of text tips at the bottom: debugging - changed to conf / server.xml This time the D: / tomcat 4.1 / conf / server.xml file configuration has changed . If you open the D: / Tomcat 4.1 / conf / server.xml file at this time, you will find a lot of content of the server.xml file. Some comments are removed. It will also find the following text to configure the web application ->
Carefully control the Server.xml file, it will find that the connection pool information just configured is placed in the "UserDatabase"> Open the D: / Tomcat 4.1 / conf / server.xml file, find the web application text just configured, because the server.xml file is automatically modified, and removes a lot of comment content, so the web application just configured The content is as follows: --------------------- <% @ page contenttype = "text / html; charset = GBK"%> <% @ page import = "javax. Naming. * "%> <% @ page import =" javax.sql. * "%> <% @ page import =" java.sql. * "%> <% try {context initX = new initialContext (); if (); if ( INitctX == NULL) Throw new exception ("There is no matching environment"); context ctx = (context) INITCTX.LOOKUP ("Java: Comp / ENV"); // Get the connection pool object Object obj = (Object) CTX. Lookup ("JDBC / MyorCl"); // Type Conversion Javax.sql.datasource DS = (Javax.sql.datasource) OBJ; if (DS == Null) Throw new Exception ("No Match Database"; connection conn = DS.GetConnection (); statement stmt = conn.createstatement (); string strsql = "select * from grade"; // SQL, to ensure that there is a record in the Grade data table. ResultSet RS = Stmt.executeQuery (STRSQL); if (rs.next ()) {Out.Println (rs.getstring (1)); Out.Println (rs.getstring (2)); // Close ResultSet Stmt.close (); // Turn Statement Conn.close (); // Put the connection back to the connection pool} catch (Exception EX) {EX.PrintStackTrace (); throw new SQLException ("Cannot Get Connection Pool. " EX);}%>
-------------------- Remember, use the database connection to be released. Otherwise when the open connection is too much or maliciously brush screen, the number of connections to the connection pool will be used. When the number of connections of the connection pool is used, when the JSP page is accessed, the following error message will appear on the page, the connection to the connection pool is exhausted: java.sql.sqlexception: DBCP COULD NOT OBTAIN An IDLE DB Connection, Pool EXHAUSTED 2 Don't forget to put Oracle's driver Classes12.jar file COPY to the directory D: / tomcat 5.0 / circon / lib / under. Tomcat5's connection pool settings and Tomcat4 are similar, and only different points or particular attention is required.
1. After Tomcat5 is started, visit http://127.0.0.1:8080/admin page, after setting the Tomcat connection pool data source, open the D: / Tomcat 5.0 / conf / server.xml file, you will see the configuration Connection pool related information is approximately as follows: