首先声明。我用的是tomcat6.0 数据库是mysql 数据库连接正常。
证据是
我用myeclipse 自带的数据查看器。正常连接能看见表。
程序是
System.out.println("1");
javax.naming.Context ctx=new javax.naming.InitialContext();
System.out.println("2");
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
System.out.println("3");
System.out.println(ds);
con=ds.getConnection();
System.out.println(con);
抛出的异常是 org.apache.tomcat.dbcp.dbcp.BasicDataSource@125b750
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
1
2
3我这样配置的 连接池
大家给看下servel.xml下面这样写 的
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/sevelet" docBase="D:\java\sevelet" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/bookstore"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bookstore"
username="root"
password="123"
maxActive="100"
maxIdle="30"
maxWait="10000" />
</context>然后在web。xml这样写的
<resource-ref>
<description>MySQL DataSource</description>
<res-ref-name>jdbc/bookstore</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
我研究了好长时间也没弄好。希望能得到大家的帮助。谢谢
证据是
我用myeclipse 自带的数据查看器。正常连接能看见表。
程序是
System.out.println("1");
javax.naming.Context ctx=new javax.naming.InitialContext();
System.out.println("2");
javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
System.out.println("3");
System.out.println(ds);
con=ds.getConnection();
System.out.println(con);
抛出的异常是 org.apache.tomcat.dbcp.dbcp.BasicDataSource@125b750
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
1
2
3我这样配置的 连接池
大家给看下servel.xml下面这样写 的
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/sevelet" docBase="D:\java\sevelet" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/bookstore"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/bookstore"
username="root"
password="123"
maxActive="100"
maxIdle="30"
maxWait="10000" />
</context>然后在web。xml这样写的
<resource-ref>
<description>MySQL DataSource</description>
<res-ref-name>jdbc/bookstore</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
我研究了好长时间也没弄好。希望能得到大家的帮助。谢谢
解决方案 »
- richfaces3.3.1实现行拖动进行排序?
- spring注释式注入不成功???
- 关于web应用防毒的问题
- 谁帮我写一个简单的放注入的代码嘛?
- (急)服务器带宽在10M/s,同时大概能支撑多少用户访问?
- 关于jboss部署ejb问题,
- 请教一个Hibernate的NoInitialContextException问题
- 问个比较傻的问题(关于servlet里url的定制)
- 小弟初学JAVA,请各位大虾给点意见?进者有分!
- 通过RMI获得远程的Connection出错……求救,在线等
- struts2.16 ajax有没什么标签返回的是一个数据结果集
- hibernate中不必要的sql update问题
你没有导入mysql的驱动程序包:mysql-connector-java-5.1.0-bin.jar
导入到项目里也行,导入到tomcat中也行
<ResourceLink
global="jdbc/bookstore" name="jdbc/bookstore"
type="javax.sql.DataSource"/>
2.你没有导入mysql的驱动程序包:mysql-connector-java-5.1.0-bin.jar
导入到项目里也行,导入到tomcat中也行
连接池的配置就是像我那样的配置没错。仅仅抛出这异常。后来改了改。琢磨下。因为你的 servlet 类没在web。xml注册的原因。