Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNDI - Cannot create resource instance (Sun One 6.1)

807567May 17 2006 — edited May 20 2006
I am trying to do JNDI in Sun One Web server 6.1 sp 5 but I seem to be missing an important part. I get two different errors based on the JSP code, �Cannot retrieve data source: javax.naming.NamingException: Cannot create resource instance� or �Cannot retrieve data source: javax.naming.NamingException: Cannot create resource instance�.

Context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/BOTest">
  <Resource name="jdbc/dev10g" auth="Container" type="javax.sql.DataSource" 
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@10.10.10.10:1521:dev10g" 
username="userid" password="password" maxActive="20" maxIdle="10" maxWait="-1"/>
  <Resource name="Data" auth="Container" type="javax.sql.DataSource" 
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@10.10.10.10:1521:dev10g" 
username="userid" password="password" maxActive="20" maxIdle="10" maxWait="-1"/>
</Context>
Sun-one.xml:
<sun-web-app>
<context-root>BOTest</context-root>
<resource-ref>
<res-ref-name>jdbc/dev10g</res-ref-name>
<jndi-name>jdbc/dev10g</jndi-name>
</resource-ref>
</sun-web-app>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
	<welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
    <resource-ref>
        <description>jdbc:oracle:thin:@10.10.10.10:1521:dev10g</description>
        <res-ref-name>jdbc/dev10g</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Application</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <resource-ref>
        <description>jdbc:oracle:thin:@10.10.10.10:1521:dev10g</description>
        <res-ref-name>Data</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Application</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
</web-app>
server.xml has:
<RESOURCES>
- <JDBCCONNECTIONPOOL name="dev10g" datasourceclassname="oracle.jdbc.pool.OracleDataSource" steadypoolsize="8" maxpoolsize="32" poolresizequantity="2" idletimeout="300" maxwaittime="60000" connectionvalidationrequired="off" connectionvalidationmethod="auto-commit" validationtablename="" failallconnections="off" transactionisolationlevel="read-uncommitted" isolationlevelguaranteed="off">
  <PROPERTY name="User" value="userid" /> 
  <PROPERTY name="URL" value="10.10.10.10" /> 
  <PROPERTY name="Password" value="password" /> 
  </JDBCCONNECTIONPOOL>
  <JDBCRESOURCE jndiname="jdbc/dev10g" poolname="dev10g" enabled="on" /> 
  <JDBCRESOURCE jndiname="Data" poolname="dev10g" enabled="on" /> 
- <JDBCCONNECTIONPOOL name="Data" datasourceclassname="oracle.jdbc.pool.OracleDataSource" steadypoolsize="8" maxpoolsize="32" poolresizequantity="2" idletimeout="300" maxwaittime="60000" connectionvalidationrequired="off" connectionvalidationmethod="auto-commit" validationtablename="" failallconnections="off" transactionisolationlevel="read-uncommitted" isolationlevelguaranteed="off">
  <PROPERTY name="URL" value="10.10.10.10" /> 
  <PROPERTY name="User" value="userid" /> 
  <PROPERTY name="Password" value="password" /> 
  </JDBCCONNECTIONPOOL>
  <JDBCRESOURCE jndiname="jdbc/Data" poolname="Data" enabled="on" /> 
  <JDBCRESOURCE jndiname="dev10g" poolname="dev10g" enabled="on" /> 
  </RESOURCES>
I am getting the following error: �Cannot retrieve data source: javax.naming.NamingException: Cannot create resource instance

With the following code:
<%@page 
   import="java.io.*,
           javax.sql.*,
           javax.naming.*,
           java.sql.*,
           java.util.*"%>

<%
Context init;
Context ctx;
DataSource datasource;
Connection con;

try
{
init = new InitialContext();
Context envCtx = (Context) init.lookup("java:comp/env");
datasource = (DataSource)  envCtx.lookup("jdbc/dev10g");
}
catch(NamingException ex)
{
    out.print("Cannot retrieve data source: " + ex.toString(true));
    return;
}

try
{
    con = datasource.getConnection();
}
catch (Exception e)
{
  out.print("Cannot retrieve connection: " + e.toString());
  return;
}

try
{
    PreparedStatement pstmt = con.prepareStatement("SELECT PROJNO FROM MATERIALSLAB.VW_ASPHALTHEADERINFO");
    ResultSet results = pstmt.executeQuery();
    while (results.next())
{
    out.println(results.getString(1));
}
}
catch(Exception ex)
{
out.print("Got connection, can't execute query: " + ex.toString());
return;
}
%>
I get the following error: Cannot retrieve data source: javax.naming.NamingException: Cannot create resource instance

With the following code:
<%@page 
   import="java.io.*,
           javax.sql.*,
           javax.naming.*,
           java.sql.*,
           java.util.*"%>

<%
Context init;
Context ctx;
DataSource datasource;
Connection con;

try
{
    init = new InitialContext();
    ctx = (Context) init.lookup("java:comp/env");
    datasource = (DataSource) ctx.lookup("jdbc/dev10g");
}
catch(NamingException ex)
{
    out.print("Cannot retrieve data source: " + ex.toString(true));
    return;
}

try
{
    con = datasource.getConnection();
}
catch (Exception e)
{
  out.print("Cannot retrieve connection: " + e.toString());
  return;
}

try
{
    PreparedStatement pstmt = con.prepareStatement("SELECT PROJNO FROM MATERIALSLAB.VW_ASPHALTHEADERINFO");
    ResultSet results = pstmt.executeQuery();
    while (results.next())
{
    out.println(results.getString(1));
}
}
catch(Exception ex)
{
out.print("Got connection, can't execute query: " + ex.toString());
return;
}
%>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 17 2006
Added on May 17 2006
3 comments
1,394 views