2 things are possible culprits....

The syntax for JNDI datasources changed slightly after moving from Tyrex as 
the default provider to DBCP.  Specifically, "user" should be 
"username".  The other thing is the <Resource scope="Sharable">.  That 
might be right, but I've never used it.  I use "Container" for that value.

Jake

At 02:07 PM 10/14/2002 +0100, you wrote:
>Hi there,
>
>I am using Oracle 9i, DBCP and Tomcat 4.1.12.  I am trying to configure a
>JNDI datasource that implements connection pooling.  I have been following
>the instructions in the JNDI how to, specifically the section for Oracle.
>
>My problem is that the JNDI Datasource is null when I try to get it from the
>context.  I cant see any exceptions being thrown anywhere.
>
>Can anyone tell me what I have missed?
>
>My server.xml is as follows (this entry is in the HOST tag, after the
>/examples context):
>
>         <Context className="org.apache.catalina.core.StandardContext"
>                  cachingAllowed="true"
>                  charsetMapperClass="org.apache.catalina.util.CharsetMapper"
>
>                  cookies="true"
>                  crossContext="true"
>                  debug="5" docBase="TestDB"
>
>mapperClass="org.apache.catalina.core.StandardContextMapper"
>                  path="/TestDB" privileged="false"
>                  reloadable="true" swallowOutput="false"
>                  useNaming="true"
>                  wrapperClass="org.apache.catalina.core.StandardWrapper">
>           <Logger className="org.apache.catalina.logger.FileLogger"
>                   debug="0" directory="logs"
>                   prefix="localhost_DBTest_log."
>                   suffix=".txt" timestamp="true" verbosity="1"/>
>           <Resource auth="container" name="jdbc/myoracle" scope="Shareable"
>type="java.sql.DataSource"/>
>           <ResourceParams name="jdbc/myoracle">
>             <parameter>
>               <name>factory</name>
>               <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>             </parameter>
>             <parameter>
>               <name>url</name>
>               <value>jdbc:oracle:thin:@127.0.0.1:1521:RHODES</value>
>             </parameter>
>             <parameter>
>               <name>password</name>
>               <value>tiger</value>
>             </parameter>
>             <parameter>
>               <name>maxActive</name>
>               <value>20</value>
>             </parameter>
>             <parameter>
>               <name>maxWait</name>
>               <value>10</value>
>             </parameter>
>             <parameter>
>               <name>driverClassName</name>
>               <value>oracle.jdbc.driver.OracleDriver</value>
>             </parameter>
>             <parameter>
>               <name>user</name>
>               <value>scott</value>
>             </parameter>
>             <parameter>
>               <name>maxIdle</name>
>               <value>10</value>
>             </parameter>
>           </ResourceParams>
>         </Context>
>
>
>And web.xml is as follows:
>
>   <resource-ref>
>     <description>Oracle Datasource example</description>
>     <res-ref-name>jdbc/myoracle</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>
>
>
>
>I have a class as follows:
>
>package foo;
>
>import javax.naming.*;
>import javax.sql.*;
>import java.sql.*;
>
>public class DBTest
>{
>   String foo = "Not Connected";
>   int bar = -1;
>
>         public void init()
>         {
>                 try
>                 {
>                         Context ctx = new InitialContext();
>                         if(ctx == null )
>                         {
>                                 throw new Exception("Boom - No Context");
>                         }
>
>                         Context envContext  =
>(Context)ctx.lookup("java:/comp/env");
>                         DataSource ds =
>(DataSource)envContext.lookup("jdbc/myoracle");
>
>                         if (ds != null)
>                         {
>                                 Connection conn = ds.getConnection();
>
>                                 if(conn != null)
>                                 {
>                                         foo = "Got Connection
>"+conn.toString();
>                                         Statement stmt =
>conn.createStatement();
>                                         ResultSet rst =
>stmt.executeQuery("select id, foo, bar from testdata");
>
>                                         if(rst.next())
>                                         {
>                                                 foo = rst.getString(2);
>                                                 bar = rst.getInt(3);
>                                         }
>
>                                         conn.close();
>                                 }
>                         }
>                         else
>                         {
>                                 System.out.println("DS was null!");
>                         }
>                 }
>                 catch(Exception e)
>                 {
>                         e.printStackTrace();
>                 }
>         }
>
>         public String getFoo() { return foo; }
>         public int getBar() { return bar;}
>}
>
>
>
>And finally, a JSP as follows:
>
><% foo.DBTest tst = new foo.DBTest(); tst.init(); %>
>
>Results
>
>
>
>Foo <%= tst.getFoo() %> Bar <%= tst.getBar() %>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to