Search code examples
javajdbcjndiconnection-pooling

Spelling error in context.xml causes another error


I've a web application with database data source defined in META-INF/context.xml.

<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>

and this is my 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>

and The problem is I get following exception when I run this code:

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

Exception : Cannot create JDBC driver of class '' for connect URL 'jdbc:oracle:thin:@localhost:1521:xe'


Solution

  • The context.xml has an error.

    The driverClassName is miss spelled.