Tomcat data source connection pool Configuration
First install the driver in the lib directory
1. First, use Tomcat's Web management to configure the data source. The following items are available:
1. JNDI name: name of the data source connection pool
2 Data source URL: JDBC: mysql: // localhost/test MySQL indicates the database type, and test indicates the database name localhost indicates the local database.
3 JDBC Driver Class: Database Driver Class MySQL uses org. gjt. Mm. MySQL. Driver
4. the user name is the database user name. 5. The password is the database password.
6 max. Active connections: Maximum number of active connections
6 max. ldle connections: Maximum number of idle connections
7 Max. Wait for connection: Maximum number of waiting connections
After completing the preceding configuration, click Save -- Commit Changes -- log out.
2. Add the following information to/CONF/Web. XML in the tomcat installation directory:
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/MySQL </RES-ref-Name> // name of the data source to be used
<Res-type> javax. SQL. datasource </RES-type> // Data Source Type
<Res-auth> container </RES-auth> // consistent
</Resource-ref>
3. Find the configuration information (project name. XML) of the current project in the/CONF/Catalina/localhost directory under the tomcat installation directory and add
<Resourcelink name = "JDBC/MySQL" Global = "JDBC/MySQL" type = "javax. SQL. datasource"/>
The above completes the configuration of the Connection Pool
The second type is
1. Put the code generated in step 1 in the/CONF/Catalina/localhost/project name. xml directory of the tomcat installation directory.
The generated code is as follows:
<Resource auth = "Container" Description = "user database that can be updated and saved" name = "userdatabase" type = "org. Apache. Catalina. userdatabase"/>
<Resource Name = "JDBC/MySQL" type = "javax. SQL. datasource"/>
<Resourceparams name = "userdatabase">
<Parameter>
<Name> factory </Name>
<Value> org. Apache. Catalina. Users. memoryuserdatabasefactory </value>
</Parameter>
<Parameter>
<Name> pathname </Name>
<Value> CONF/tomcat-users.xml </value>
</Parameter>
</Resourceparams>
<Resourceparams name = "JDBC/MySQL">
<Parameter>
<Name> URL </Name>
<Value> JDBC: mysql: // localhost/test </value>
</Parameter>
<Parameter>
<Name> password </Name>
<Value> </value>
</Parameter>
<Parameter>
<Name> maxactive </Name>
<Value> 4 </value>
</Parameter>
<Parameter>
<Name> maxwait </Name>
<Value> 5000 </value>
</Parameter>
<Parameter>
<Name> driverclassname </Name>
<Value> org. gjt. Mm. MySQL. Driver </value>
</Parameter>
<Parameter>
<Name> username </Name>
<Value> root </value>
</Parameter>
<Parameter>
<Name> maxidle </Name>
<Value> 2 </value>
</Parameter>
</Resourceparams>
2. Add the following information to/CONF/Web. XML in the tomcat installation directory:
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/MySQL </RES-ref-Name> // name of the data source to be used
<Res-type> javax. SQL. datasource </RES-type> // Data Source Type
<Res-auth> container </RES-auth>
</Resource-ref>
The difference between the two is that they have different scopes.
Database connection test:
Initialcontext CTX = new initialcontext ();
DS = (datasource) CTX. Lookup ("Java: COMP/ENV/jdbc/MySQL ");
Conn = Ds. getconnection ();
Question displayed in Chinese:
Public static string tochinese (string strvalue ){
Try {
If (strvalue = NULL)
{
Return NULL;
}
Else {
Strvalue = new string (strvalue. getbytes ("iso8859_1"), "GBK ");
Return strvalue;
}
} Catch (exception e ){
Return NULL;
}
}