0

我有一个在 META-INF/context.xml 中定义的数据库数据源的 Web 应用程序。

<Context>
    <Resource name="jdbc/MYJNDI"
              auth="Container"
              type="javax.sql.DataSource"
              username="Arash"
              password="who"
              driverClassNmae="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@localhost:1521:xe"
              maxActive="10"
              maxIdle="1"/>

</Context>

这是我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
    <resource-ref>
        <description>Oracel + jndi test</description>
        <res-ref-name>jdbc/MYJNDI</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>

问题是当我运行此代码时出现以下异常:

Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/MYJNDI");
**connection = ds.getConnection();**

异常: 无法为连接 URL 'jdbc:oracle:thin:@localhost:1521:xe' 创建类 '' 的 JDBC 驱动程序

4

1 回答 1

0

context.xml错误。

driverClassName拼写错误。

于 2013-06-21T20:10:25.953 回答