我用的是:MYSQL SERVER 5.5,Eclipse SDK 3.1.1,tomcat 5.5.12解压版.
server.xml配置如下:
<Context path="/test" docBase="d:\workspace\test" debug="5" reloadable="true" crossContext="true" workDir="d:\workspace\test\work">
<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource" factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bbs?autoReconnect=true"/></Context>
web.xml配置如下:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
java程序代码如下:
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Context ctx=null;
DataSource ds=null;
try {
ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
conn=ds.getConnection();
stmt = conn.createStatement();
int count = stmt.executeUpdate("insert into temp values('" + msg + "')");
} catch (SQLException sqle) {
out.println("SQLException:" + sqle.toString());
} catch (Exception e) {
e.printStackTrace();
}
报错信息为:
SQLException:org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
请问各位大大,这是怎么回事?
server.xml配置如下:
<Context path="/test" docBase="d:\workspace\test" debug="5" reloadable="true" crossContext="true" workDir="d:\workspace\test\work">
<Resource name="jdbc/test" auth="Container" type="javax.sql.DataSource" factory="org.apache.commons.dbcp.BasicDataSourceFactory"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bbs?autoReconnect=true"/></Context>
web.xml配置如下:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
java程序代码如下:
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
Context ctx=null;
DataSource ds=null;
try {
ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
conn=ds.getConnection();
stmt = conn.createStatement();
int count = stmt.executeUpdate("insert into temp values('" + msg + "')");
} catch (SQLException sqle) {
out.println("SQLException:" + sqle.toString());
} catch (Exception e) {
e.printStackTrace();
}
报错信息为:
SQLException:org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
请问各位大大,这是怎么回事?
classpath=
%JAVA_HOME%\lib\dt.jar;
%JAVA_HOME%\lib\tools.jar;
C:\apache-tomcat-5.5.12\apache-tomcat-5.5.12\common\lib\servlet-api.jar;
%JAVA_HOME%\lib\mysql-connector-java-3.1.11-bin-g.jar;
D:\mysql-connector-java\mysql-connector-java-3.1.11-bin.jar;
D:\Jakarta-Commons\commons-collections.jar;
D:\Jakarta-Commons\commons-dbcp-1.2.1.jar;
D:\Jakarta-Commons\commons-pool-1.2.jar
好象没错呀