After a long time today, I finally successfully configured the tomcat5.0 Mysql Data Source. At first, the error "cannot create JDBC driver of class ''for connect URL 'null', cause: no suitable driver" always appears. Now I will write down my experiences on successful configuration. 1. First download the JDBC driver for MySQL, I am using a mysql-connector-java-5.0.3-bin.jar, put it under the % atat_home % common/lib directory. Because the data source configured in this way requires the Tomcat server to connect to the database using the JDBC driver, the JAR file can be loaded only when the server is started. 2. I use myeclipse to create a project (for example, the project name is datasource) and publish it to the Tomcat server. In this way, a datasource. xml file is created in % atat_home % CONF/Catalina/localhost. This should be the context of the project on the server. The data source is configured here. 3. The content of this datasource. xml file is: <? XML version = '1. 0' encoding = 'utf-8'?> <Context docbase = "D: /tomcat 5.0/webapps/datasource "Path ="/datasource "workdir =" work/Catalina/localhost/datasource "> <resource auth =" Container "name =" JDBC/datasource" type = "javax. SQL. datasource "/> <resourcelink name =" JDBC/datasource "Global =" JDBC/datasource "type =" javax. SQL. datasource "/> // actually use this <Resource Name =" JDBC/datasource "type =" javax. SQL. datasource "/> // I replaced <resourceparams name =" JD BC/datasource "> <parameter> <Name> maxwait </Name> <value>-1 </value> </parameter> <Name> maxactive </Name> <value> 200 </value> </parameter> <Name> password </Name> <value> root </value> </parameter> <name> URL </Name> <value> JDBC: mySQL: // localhost: 3306/archives? Autoreconnect = true </value> </parameter> <Name> driverclassname </Name> <value> COM. mySQL. JDBC. driver </value> </parameter> <Name> maxidle </Name> <value> 0 </value> </parameter> <Name> username </Name> <value> root </value> </parameter> </resourceparams> </context> 4. however, at the beginning, I configured the data source in Tomcat administration, but Tomcat is in % atat_home % CONF/Catalina/localhost/server. red above is added to XML Copy it to % atat_home % CONF/Catalina/localhost/datasource. XML, as shown above. And set <Resource Name = "JDBC/datasource" type = "javax. SQL. change datasource to <resourcelink name = "JDBC/datasource" Global = "JDBC/datasource" type = "javax. SQL. datasource "/>. 5. finally, in the web. add <resource-ref> <res-ref-Name> JDBC/datasource </RES-ref-Name> <res-type> javax. SQL. datasource </RES-type> <res-auth> container </RES-auth> </resource-ref> 6. write a JSP file for testing. <%... @ page import = "Java. io. *, Java. util. *, Java. SQL. *, javax. SQL. *, javax. naming. * "%>
<%... @ Page contenttype = "text/html; charset = gb2312" %>
<HTML>
<Head> <title> your se connection test </title> <Body>
<%...
Try {
Statement stmt;
Resultset RS;
Javax. Naming. Context CTX = new javax. Naming. initialcontext ();
Javax. SQL. datasource DS = (javax. SQL. datasource) CTX. Lookup ("Java: COMP/ENV/jdbc/datasource ");
Java. SQL. Connection con = Ds. getconnection ();
Stmt = con. createstatement ();
Rs1_stmt.exe cutequery ("select * from user ");
While (Rs. Next ()){
Out. Print (Rs. getint (1 ));
Out. Print (Rs. getstring (2 ));
}
Rs. Close ();
Stmt. Close ();
Con. Close ();
} Catch (exception e ){
Out. Print (E. getmessage ());
}
%>
</Body>
</Html>