Tomcat45 connection pool settings

xiaoxiao2021-03-05  32

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. Set the driver of the database

Take Oracle's JDBC driver settings as an example:

Oracle8i driver 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:

After completing, becomes this:

->

Save the D: / Tomcat 4.1 / conf / server.xml file.

After the configuration is complete, restart Tomcat can be accessed this way: http://127.0.0.1:8080/mypool/.

4. Set the Tomcat connection pool data source.

Access http://127.0.0.1:8080/admin page, log in with the username and password fill in the Tomcat4 just installed.

After the login is successful, Tomcat Web Server Administration Tool will appear.

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 - Changes Saved 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 ->

It is automatically modified to this:

Ok, to this position, the connection pool for Oracle has been configured. Carefully control the Server.xml file, you will find that the connection pool information just configured is placed in the tab, which means that this information can be grouped by globally, which is approximately as follows:

maxwait 5000 maxactive 200 Password mypassword URL jdbc: Oracle: Thin: @ 192.168. 6.40: 1521: DBSERVER driverclassname Oracle.jdbc.driver.OracleDriver maxidle < / Name> 20 username myname

Automatic modification is this:

In the description of , add this web application to the reference description of the global connection pool, as follows:

After the setting is complete, the description of the web application is approximately as follows:

Save D: / Tomcat 4.1 / conf / server .xml file.

Note that the reference description of this connection pool is a very important step. Some friends configure the connection pool failure in Tomcat4, most of them. There are also some online articles that this is a bug of Tomcat4. I used it for two days and two nights to understand the mystery. [:(] At that time, only a little bit was checked. Because it is simple to configure a connection pool. [:(]

6. Usually, here, the setting of the connection pool is completed.

Then you need to restart Tomcat so you can use the connection pool to work.

However, I saw a lot of articles that I also need to set up Web.xml to apply. I didn't set up Web.xml, and the connection pool can also be fully used.

Now let's talk about the configuration method of web.xml.

Built a new folder in D: / MyPool, named Web-INF, pay attention to the uppercase letters.

Then create a new file web.xml in D: / MyPool / Web-INF / under:

Oracle DataSource Example JDBC / MyorCl javax.sql.datasource Container

Save the D: /MyPool/web-inf/web.xml file.

7. A simple application example.

Write a simple JSP page that accesses the database with the connection pool.

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));}}} rc. (); // Close ResoltSet Stmt.close (); // Turn the 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, the configuration of the Tomcat5 connection pool under Win2k

Install Jakarta-Tomcat-5.0.13.exe, if Tomcat5 installation directory is D: / Tomcat 5.0.

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 The connection pool related information is approximately as follows:

maxWait 5000 maxactive 4 password mypassword URL jdbc: oracle: Thin: @ 127.0.0.1: 1521: dbserver driverclassname Oracle.jdbc.driver.Oracledriver maxidle 2 username myusername factory org.apache.catalina.users.MemoryUserDatabaseFactory < / value>

pathname conf / tomcat-users.xml can be seen, some connection pools are different from Tomcat4. . However, the rough configuration steps and methods are the same.

2. Set the reference to the connection pool.

Open the D: / Tomcat 5.0 / conf / Catalina / localhost / directory, find the XML file (MyPool.xml) with the web app, open this file, repair the description of this , add the following line :

Make the content of mypool.xml files to this:

Then save MyPool.xml, you need to re-Tomcat5 service to take effect.

3. JSP page Test file is also the same, no longer described again.

4. Some supplements:

If the web application is not configured with the reference to the connection pool, it is not configured , the following error occurs when accessing the JSP page: NameNotFoundException: Name JDBC is Not Bound in this Context

If the Oracle's JDBC driver is missing, the following error occurs when the JSP page is accessed: java.sql.sqlexception: Cannot Load JDBC Driver Class 'Oracle.jdbc.driver.Orcledriver'

转载请注明原文地址:https://www.9cbs.com/read-32063.html

New Post(0)