【发布时间】:2016-06-14 17:04:10
【问题描述】:
我正在尝试使用 jndi 查找来获取连接池,但出现以下错误:java.sql.SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
我的上下文 xml 放在 web.xml 附近的 web/WEB-INF 文件夹中
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" crossContext="true" reloadable="true" path="patient/account">
<Resource
name="jdbc/pharmacy"
author="Container"
type="javax.sql.DataSource"
maxActive="32"
maxIdle="8"
maxWait="10000"
username="root"
password="23810198vas"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/pharmacy" />
</Context>
Context envCtx = new InitialContext();
DataSource ds = (DataSource)envCtx.lookup("java:comp/env/jdbc/pharmacy");
Connection connection = ds.getConnection();
【问题讨论】:
-
对于 Tomcat,context.xml 应该在 META-INF 和 META-INF 文件夹应该在同一级别 WEB -INF 文件夹。
-
谢谢!它现在正在工作
标签: mysql jndi connection-pooling