Every project will take a while to work on the database. It was easy to handle in the past because it was all based on TOMCAT5.0. Whether it was equipped with ORCALE SQLSERVER2000 or MYSQL, I have been used to it for a long time. But I have never expected to use TOMCAT5 again. .5 To do this, I am accustomed to using TOMCAT5.5 only in the proxool.xml configuration method. But I have always believed that TOMCAT5.5 can be used in all methods. Because configuration is just a method.
I worked on it all day yesterday, and finally reported an error like Cannot create JDBC driver of class '' for connect URL 'null' when using the database. I thought it must be the same as before, but there must be a mistake in the configuration file somewhere, but after checking for a long time, there was not even a word written. I checked online by mistake, and it turns out that many brothers have encountered the same problem as me. I tried according to a brother's writing method but failed. During the TOMCAT5.0 period, we configured it like this in XXX.XML in TOMCAT_HOMEconfCatalinalocalhost. database path
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="D:eclipseworkspaceBKGMS" path="/BKGMS" reloadable="true" workDir="D:eclipseworkspaceBKGMSworkorgapachejsp">
<Resource auth="Container" name="RedstoneSql" type="javax.sql.DataSource"/>
<ResourceParams name="better">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bkgms</value>
</parameter>
<parameter>
<name>password</name>
<value>sa</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
</ResourceParams>
</Context>
According to a brother's writing method, add <ResourceLink global="better" name="better" type="javax.sql" before <Resource auth="Container" name="better" type="javax.sql.DataSource"/> .DataSource"/> can be done, but after restarting TOMCAT, it reports "unable to get connection: no suitable driver"
Damn it, I think this is not working, let’s check again. Most brothers have said that the configurations of TOMCAT5.5 and TOMCAT5.0 are different. Since Tomcat5.5, the <Resoucepram> element of the <context> element has been cancelled, and the original parameter element All appear as attributes of Resource.
Instead, it should be written like this, adding <ResourceLink> by the way.
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="D:eclipseworkspaceBKGMS" path="/BKGMS" reloadable="true" workDir="D:eclipseworkspaceBKGMSworkorgapachejsp">
<Resource auth="Container" name="better" type="javax.sql.DataSource" maxWait="10000" maxIdle="30" maxActive="100" username="sa" password="sa" driverClassName="com .microsoft.jdbc.sqlserver.SQLServerDriver" url="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bkgms"/>
<ResourceLink global="better" name="better" type="javax.sql.DataSource"/>
</Context>
Explain: 1.path is the URL entry that specifies access to the web application;
2.docBase specifies the file path of the web application, which can be an absolute path or a relative path relative to the appBase attribute of the Host;
3.type
4.maxActive It is the maximum number of active database connections in DBCP. 0 means unlimited
. 5. maxIdle is the maximum number of idle database connections in DBCP. 0 means unlimited
6. maxWait is the database in DBCP. The maximum time for the connection to be idle (in milliseconds) is 0, which means waiting indefinitely.
7. username is the database login name.
8. password is the database login password.
9. driverClassName is the jdbc driver for the database only
. 10. url is specified. The URL to connect to the database, testDBCP is my database name.
The report "unable to get connection: no suitable driver"
is to start tomcat from eclipse. It is found that org.apache.commons.dbcp.BasicDataSourceFactory cannot be found during startup, so factory="org.apache.commons.dbcp.BasicDataSourceFactory" in the Resouce element is reported. "Delete and the error is resolved.
Of course don’t forget to add in web.xml
<resource-ref>
<description>DB Connection</description>
<res-ref-name>better</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
However, if you use SQLSERVER2000, you must also ensure that the SP4 patch is applied.