Add Resource in Tomcat 5.5/CONF/Catalina/localhost/XXXXX. XML (XXXXX. XML is your web configuration XML file)
<Resource Name = "MySQL"
Type = "javax. SQL. datasource"
Driverclassname = "com. MySQL. JDBC. Driver"
Password = "********"
Maxidle = "2"
Maxwait = "5000"
Username = "root"
Url = "JDBC: mysql: // localhost: 3306/jnestore"
Maxactive = "10"/>
The above is the configuration of Tomcat 5.5. Only in this way can Tomcat 5.5 be effective. Previous versions can be added as paramter;
Resource must be included between <context...> </context>
Find web. XML in your WEB-INF, add resource ing
<Resource-ref>
<Description> connection </description>
<Res-ref-Name> mysql </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
Put MySQL JDBC driver. jar package in Tomcat common/lib down, you can also put in WEB-INF/lib,
Restart tomcat.
You can use context CTX = new initialcontext ();
Datasource DS = (datasource) CTX. Lookup ("Java: COMP/ENV/MySQL ");
Connection con = Ds. getconnection (); to connect to the Database Connection Pool