tomcat的conf目录下的context.xml的配置如下
<Context reloadable="true"> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="214845"
driverClassName="com.mysql.jdbc.Driver" url=="jdbc:mysql://localhost:3306/txmusic"/>
</Context>mysql的驱动包在工程的lib和tomcat的lib下都有,
jsp页面本来用JDBC的传统模式连入数据库,没问题
现在换成 Context context=new InitialContext();
DataSource ds=(DataSource)context.lookup("java:/comp/env/jdbc/mysql");
conn=ds.getConnection();就不行了,运行web就显示org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class '
请高手指点,非常感谢
conn=ds.getConnection();
<Context reloadable="true"> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="214845"
driverClassName="com.mysql.jdbc.Driver" url=="jdbc:mysql://localhost:3306/txmusic"/>
</Context>mysql的驱动包在工程的lib和tomcat的lib下都有,
jsp页面本来用JDBC的传统模式连入数据库,没问题
现在换成 Context context=new InitialContext();
DataSource ds=(DataSource)context.lookup("java:/comp/env/jdbc/mysql");
conn=ds.getConnection();就不行了,运行web就显示org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class '
请高手指点,非常感谢
conn=ds.getConnection();
解决方案 »
- HttpServletRequest .getRealPath("/") 时 报java.lang.IllegalAccessError 错误
- struts 页面无法显示 ${}
- 急急~~~~~~~~~~~!!!!!!!!!!!!!
- 在任务栏里显示图标
- Tomcate5.5不配数据库连接池的性能问题
- 用JSP怎么样判断当前操作系统?
- 在JSP文件中用JAVAScript脚本怎么老有问题,
- 具体的解释一下JavaBeans 的Scope 属性
- 表单在页面之间传地数据时,发现中文都变成了“???”,请教
- 为什么我一用就出现ResultSet已经关闭的错误?
- struts2 迭代问题
- struts2 date校验器使用?
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
web.xml configuration
测试项目中:
在<web-app></web-app>这对元素中加入如下内容:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
jsp页面本来用JDBC的传统模式连入数据库,没问题
现在换成 Context context=new InitialContext();
DataSource ds=(DataSource)context.lookup("java:/comp/env/jdbc/mysql");
conn=ds.getConnection();就不行了,运行web就显示org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class '
请高手指点,非常感谢红色字体的你写错了。应该为:ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/mysql");