java Error while connecting oracle datasource from Jboss 6.3 server

22:25:32,256 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/TestDatasource].[jsp]] (http-/127.0.0.1:8080-2) JBWEB000236: Servlet.service() for servlet jsp threw exception: javax.naming.NameNotFoundException: comp/env — service jboss.naming.context.java.comp.env
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:103)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:241)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at javax.naming.InitialContext.lookup(Unknown Source) [rt.jar:1.8.0_25]
at javax.naming.InitialContext.lookup(Unknown Source) [rt.jar:1.8.0_25]
at com.java.DBConnection.getConnection(DBConnection.java:27) [classes:]
at org.apache.jsp.index_jsp._jspService(index_jsp.java:66)

web.xml

<resource-ref>
        <description>Oracle Datasource example</description>
        <res-ref-name>java:jboss/datasources/<datasource name></res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>

standalone.xml

<datasource jta="false" jndi-name="java:jboss/datasources/<datasource name>"     pool-name="<pool name>" enabled="true" use-ccm="false">
                <connection-url>jdbc:oracle:thin:@111.95.61.18:2008:OWDM</connection-url>
                <driver-class>oracle.jdbc.OracleDriver</driver-class>
                <driver>oracleDS</driver>
                <security>
                    <user-name>OW_TAXLOT</user-name>
                    <password>OW_TAXLOT</password>
                </security>

            </datasource>

                <driver name="oracleDS" module="com.oracle.ojdbc6">
                    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                </driver>
            </drivers>

Module.xml

<module xmlns="urn:jboss:module:1.0" name="com.oracle.ojdbc6">
    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

DBConnection.java

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


Source: java

Leave a Reply