Break through the JNDI connection pool (configure the connection pool through the management interface under Tomcat5.5)
Author:Eve Cole
Update Time:2009-07-03 16:56:20
Breaking the JNDI connection pool - -
After several days of hard work, I can finally connect to the connection pool. I have referred to many posts by heroes in this regard. Now I will write down several problems that have arisen in the past few days here:
1. Put the three jdbc drivers (must) under tomcat_homecommon, which can be downloaded from Microsoft's website. The default user name of the installed SQLSERVER2k is sa, and the password is empty, but it does not matter if the password is empty. It means there is no password, so you must define username and password in your URL. It is best to reset the password. If there is an error that cannot be quoted, it is usually because the path is not written correctly. The default path of tomcat is tomcat_homewebapps, but use 5.5 .x, just follow the method below. There is no need to configure the path, and there is no need to configure the reference in the youwebappWEB-INFweb.xml file. The server.xml configuration of tomcat5.5.x version is different from the configuration of tomcat5.0 , the following are three configuration methods in tomcat5.5.x. If the configuration is incorrect, javax.naming.NameNotFoundException: Name is not bound in this Context Error method 1. Global database connection pool
1. Configure the connection pool through the management interface, or directly add it to GlobalNamingResources in tomcatconfserver.xml
<Resource name="jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000" validationQuery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb" maxActive="4"/>
2. Add the following to the Context of tomcatwebappsmyappMETA-INFcontext.xml:
<ResourceLink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>
That's it.
Method 2. Global database connection pool
1. Same as above
2. Add the following to the Context of tomcatconfcontext.xml:
<ResourceLink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>
Method 3: The local database connection pool only needs to be added to the Context of tomcatwebappsmyappsMETA-INFcontext.xml:
<Resource name="jdbc/mydb" type="javax.sql.DataSource" password="mypwd" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" maxIdle="2" maxWait="5000" validationQuery="select 1" username="sa" url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb" maxActive="4"/>
Parameter description:
driveClassName: The complete name of the JDBC driver class;
maxActive: The maximum number of available instances that can be allocated from the connection pool at the same time;
maxIdle: The maximum number of connections that can be idle in the connection pool at the same time;
maxWait: maximum timeout, in milliseconds;
password: user password;
url: URL connection to JDBC;
user: user name;
validationQuery: used to query idle connections in the pool.
The above three methods are all available under tomcat 5.5.4. In addition, the jdbc driver of sql server is sql server jdbc (sp3) downloaded from the Microsoft website.
4. Error org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory ([Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.) This is a small problem because my SQLSERVER2K service has been changed to manual , so you have to manually start SQLSERVER2K after each startup. Since it started without remembering, some errors are reported, so if you often use SQLSERVER2K, it is best not to change it to manual startup.