I'm answering my own question on this.  I found my solution here:

http://marc.theaimsgroup.com/?l=tomcat-user&m=102225547106556&w=2

The one thing I added was a slightly different Java code snippet since I 
return a Connection rather than grab the DataSource and use the connection 
right there:

import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

.....
.....
......

public static Connection getConnection() throws SQLException {
         DataSource ds = null;
         try {
             Context ctx = new InitialContext();
             if (ctx == null) throw new SQLException("No Context available 
for DataSource...can't get connection");
             ds = (DataSource)ctx.lookup("java:comp/env/jdbc/utasklistDB");
             if (ds == null) throw new SQLException("No DataSource 
available for Connection");
             System.out.println("The Datasource is: " + ds);
         }
         catch (NamingException ne) {
             throw new SQLException("JNDI Lookup Failed: " + ne.getMessage());
         }
         return ds.getConnection();
     }


There you go.  The instructions provided by Les Hughes at the link above 
and the code I added here worked perfectly for me.  Thanks to Les for 
providing this info!

Jake

At 06:13 PM 5/23/2002 -0500, you wrote:

>I've got a question about setting up a connection pool using DBCP.
>Back when I was testing the nightly build from 20020404, I could swear
>I was getting back a PooledDataSource.  Now with todays build
>(20020523), I am getting back a BasicDatasource.
>
>The code that I have looks like:
>
>         DataSource ds = null;
>         try {
>             Context initCtx = new InitialContext();
>             Context envCtx = (Context) initCtx.lookup("java:comp/env");
>             if (envCtx!=null) {
>                 ds = (DataSource)envCtx.lookup("jdbc/utasklistDB");
>                 System.out.println("The Datasource is: " + ds);
>             }
>         }
>         catch (NamingException ne) {
>             System.out.println("JNDI Lookup Failed: " + ne.getMessage());
>         }
>         return ds.getConnection();
>
>What prints out on that first println is:
>The Datasource is: org.apache.commons.dbcp.BasicDataSource@22220f
>
>Then, when I attempt to return the connection, I end up getting the
>following error:
>
>java.lang.NullPointerException
>         at java.util.Hashtable.put(Hashtable.java:380)
>         at 
> org.apache.commons.dbcp.BasicDataSource.createDataSource(Unknown Source)
>         at org.apache.commons.dbcp.BasicDataSource.getConnection(Unknown 
> Source)
>         at 
> 
>com.syntegra.unilever.tasklist.data.ConnectionManager.getConnection(ConnectionManager.java:73)
>         at 
> com.syntegra.unilever.tasklist.data.Manager.openConn(Manager.java:22)
>         at 
> 
>com.syntegra.unilever.tasklist.data.UserManager.getUserByUsername(UserManager.java:201)
>         at 
> 
>com.syntegra.unilever.tasklist.services.ValidationServices.validateUser(ValidationServices.java:91)
>         at 
> 
>com.syntegra.unilever.tasklist.services.ValidationServices.validateUser(ValidationServices.java:69)
>         at 
> 
>com.syntegra.unilever.tasklist.MasterEventGateway$LocalRequestHandler.handleControlEvent(MasterEventGateway.java:80)
>         at 
> 
>org.enhydra.barracuda.core.event.DefaultBaseEventListener.handleEvent(DefaultBaseEventListener.java:64)
>         at 
> 
>org.enhydra.barracuda.core.event.DefaultEventDispatcher.notifyListeners(DefaultEventDispatcher.java:381)
>         at 
> 
>org.enhydra.barracuda.core.event.DefaultEventDispatcher.dispatch(DefaultEventDispatcher.java:183)
>         at 
> 
>org.enhydra.barracuda.core.event.DefaultEventDispatcher.dispatchEvent(DefaultEventDispatcher.java:103)
>         at 
> 
>org.enhydra.barracuda.core.event.DefaultEventBroker.dispatchEvent(DefaultEventBroker.java:488)
>         at 
> 
>org.enhydra.barracuda.core.event.ApplicationGateway.handleDefaultExt(ApplicationGateway.java:413)
>         at 
> 
>org.enhydra.barracuda.core.event.ApplicationGateway.handleDefault(ApplicationGateway.java:239)
>         at 
> 
>org.enhydra.barracuda.core.event.ApplicationGateway.doGet(ApplicationGateway.java:632)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown 
> Source)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
>         at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown 
> Source)
>         at 
> 
>org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown
> 
> Source)
>         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
>         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
>         at org.apache.catalina.core.StandardContextValve.invoke(Unknown 
> Source)
>         at 
> 
>org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown
> 
> Source)
>         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
>         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
>         at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
>         at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
>         at 
> 
>org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown
> 
> Source)
>         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown 
> Source)
>         at 
> 
>org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown
> 
> Source)
>         at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
>         at 
> 
>org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown
> 
> Source)
>         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
>         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
>         at org.apache.catalina.core.StandardEngineValve.invoke(Unknown 
> Source)
>         at 
> 
>org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown
> 
> Source)
>         at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
>         at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
>         at 
> org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:458)
>         at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:551)
>         at java.lang.Thread.run(Thread.java:484)
>
>
>So...
>
>First, should BasicDataSource rather than PooledDataSource be
>returned?  If so, why?  How do I utilize a database pool?
>
>Second, why the null pointer at ds.getConnection()?  I wasn't getting
>that before in my previous nightly build, although I was having other
>issues where it wasn't working, which I won't get into here, but 
>ds.getConnection() did return a
>Connection object rather than throw a null pointer exception.
>
>Any hints as to what is up with this?  I realize that this is alpha
>software, but I'd like to know if I'm even on the right track or if
>something in the design has changed...and maybe I should be using DBCP
>some different way than I am now???
>
>Jake
>
>
>--
>Best regards,
>  Jacob                          mailto:[EMAIL PROTECTED]
>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to