连接池的 JNDI 查找

JNDI lookup for connection pooling

我正在尝试使用 jndi 查找获取连接池,但出现以下错误:java.sql.SQLException: 无法为连接 [=28= 创建 class '' 的 JDBC 驱动程序] '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文件夹在同一层。