Tomcat4.1.31 database connection pool configuration

xiaoxiao2021-03-05  21

(Excerpted from Java Chinese Station)

This article is used when the author is used by the blog of the Liao brother. When you start using Tomcat5.0.27, then use Tomcat5.5.4, but the configuration database has the total error, and then the Context flag is canceled. My sexual situation, I can use Tomcat4.1.31. Mainly refer to the article of Fanyhan et al., Introduced the configuration of the database connection pool under Tomcat4.1.31, and the JNDI lookup of the connection pool, and provides the corresponding test code. Finally, the common problems and solutions in the configuration and application process are pointed out. I. Tomcat introduction Tomcat is one of the subprojects of Apache Jakarta, which is a JSP recommended by Sun. As an excellent application server, Tomcat provides many universal component functions such as database connection pools, SSL, Proxy, where the connection pool is a new feature of 4.0 or higher, and the application is very extensive. Second, the text configuration environment Tomcat4.1.31 JDK1.4.2 SQL Server 2000 Win2000 AS 3 The JNDI name is set to jdbc / blog. The database server IP is localhost, SID is Blog, and the configuration steps are as follows.

Step 1: Configure server.xml to find -> Change to: factory org.apache.commons.dbcp.basicDataSourceFactory DriverclassName com.microsoft.jdbc.sqlser.sqlserverdriver URL jdbc: Microsoft: SQLServer: // localhost: 1433; DatabaseName = blog username sa Password sa < / value> maxactive 20 maxidle 20 < / parameter> maxwait -1 parameter description: Resource item : resource item (ie the DataSource object of the connection pool), there are 3 attributes name, auth, type, name item is JNDI's name definition, the program can find this object through JNDI,

Here, the JDBC / SBLOG; the Auth item is connected to the pool management rights attribute, this is the value of container, which is stated as a container management; Type item is the type of object, this is the value javax.sql.datasource, which is declared as a database connection pool. In the next domain content contains four parameters User, Password, DriverClassName, Drivername, in turn, the username, password, JDBC driver, and database address of the database. Factory Parameters: factory org.apache.commons.dbcp.basicdataroup.-Value> is the base object factory, here is values ​​org.apache.commons.dbcp. BasicDataSourceFactory, the factory that is self-contained, or other. DriverclassName parameters: driverclassname com.microsoft.jdbc.sqlser.sqlserverdriver , the database's JDBC driver name, the specific value is: SQL Server 2000: COM .microsoft.jdbc.sqlser.sqlserverdriver first to download the installation SQLSerVer-JDBC-driver, then put the three JAR files under its lib into Tomcat / Common / Lib. Mysql: org.gjt.mm.mysql.driver mysql JDBC driver package mm.mysql-2.0.14.jar. Oracle8.1.7: Oracle.jdbc.driver.OracleDriver Oracle8.1.7 JDBC Driver Package Name Classes.jar, generally located in ORA81 / JDBC / LIB directory in the Oracle installation directory, initial extension is ZIP, need to manually put Classes. ZIP is named Classes.jar and put it under Tomcat / Common / LIB. Oracle.jdbc.driver.Orcledgedriver This class is provided by classes.jar. URL parameters: URL jdbc: Microsoft: SQLServer: // localhost: 1433; DatabaseName = Blog is the address of the database. (Different databases are different) UserName Parameters: Username SA is a username connected to the database. Password parameter: password ** is a password to connect to the database.

MaxActive, Maxidle and Maxwait Parameters: maxactive 20 maxidle 20 < / parameter> maxwait -1 maxactive is the maximum number of connections, with a value of 20, indicating up to 20 database connections. MaxIdle is the maximum number of idle connections, which is 20 here, which can still keep 20 idle connections even when there is no database connection, and is not cleared, at any time in standby. MaxWait is the maximum number of seconds, here is all -1, indicating unlimited waits until the timeout can be taken, and the value is 9000, indicating 9 seconds. Step 2: Configure web.xml to open WebApps / root / web-infers Web.xml, add the following: SQLServer DataSource Example JDBC / Blog javax.sql.datasource Container third part: configure Tomcat (Add Class) Copy the three JAR files in the Microsoft SQL Server 2000 Driver for JDBC / LIB directory to the common / lib of the Tomcat installation directory. Configuration is complete! ! Fourth, the test code database is as follows: Create a database called blog, create a table inside: Create Table Test (ID varchar (12), name varchar (30)); writing a JSP file (TestDb.jsp), will Place in a WebApps / root directory, open Tomcat to run the page for testing.

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

New Post(0)