You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Carpenter <pa...@mac.com> on 2003/01/04 09:55:25 UTC

Setting up a JNDI entry for Sybase

Hi

Has anyone managed to get Tomcat talking to Sybase via a JNDI resource?

I'm very close, following the MySQL examples I can find, and of course,  
the Tomcat documentation...

But I get the following two errors at present:
javax.naming.NameNotFoundException: Name java:comp is not bound in this  
Context
         at  
org.apache.naming.NamingContext.lookup(NamingContext.java:811)
         at  
org.apache.naming.NamingContext.lookup(NamingContext.java:194)
         at com.pec.DBmultileague.testDB.init(testDB.java:30)

java.sql.SQLException: Cannot load JDBC driver class 'null'
         at  
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource 
.java:529)
         at  
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja 
va:312)
         at com.pec.DBmultileague.testDB.init(testDB.java:30)

Where the code looks like this (line 30 is the last presented here):
       Context ctx = new InitialContext();
       if(ctx == null )
         throw new Exception("Boom - No Initial Context");

       Context envCtx = (Context)ctx.lookup("java:comp/env");
       if(envCtx == null )
         throw new Exception("Boom - No Environmental Context");

       DataSource ds =  
(DataSource)envCtx.lookup("java:comp/env/jdbc/DBmultileague");


I'm sure I'm close, and my server.xml and web.xml both seem to comply  
to the rules. Is there something I need to do to have InitialContext  
java:comp/env recognised?

Thanks
Paul

FYI
Tomcat 4.1.12
Sybase 12.5
MAC OSX 10.2.3
jconn2.jar in place $CATALINA_HOME/common/lib (as well as the DBCP,  
etc, jars)

Re: Setting up a JNDI entry for Sybase

Posted by Paul Carpenter <pe...@yt.catv.ne.jp>.
Whoops...small piece of mis-information in the first post:

I get the following error at line 33:
java.sql.SQLException: Cannot load JDBC driver class 'null'

When I change the code thus:
       Context initCtx = new InitialContext();
       if(initCtx == null )
         throw new Exception("Boom - No Initial Context");

       Context envCtx = (Context) initCtx.lookup("java:comp/env");
       if(envCtx == null )
         throw new Exception("Boom - No Environmental Context");

       DataSource ds = (DataSource)  
initCtx.lookup("java:comp/env/jdbc/DBmultileague");

       if (ds != null) {
         Connection conn = ds.getConnection();


Which tells me two things (I think?):
1. An InitialContext is special and different from a plan old Context,  
despite the type-casting.
2. Both Context lookups work, but when you reference java:comp:env from  
the envCtx, for some reason that will not work.

But I still don't know why the ds.getConnection doesn't fails?  
Confused...

Paul

On Saturday, January 4, 2003, at 05:55  PM, Paul Carpenter wrote:

> Hi
>
> Has anyone managed to get Tomcat talking to Sybase via a JNDI resource?
>
> I'm very close, following the MySQL examples I can find, and of  
> course, the Tomcat documentation...
>
> But I get the following two errors at present:
> javax.naming.NameNotFoundException: Name java:comp is not bound in  
> this Context
>         at  
> org.apache.naming.NamingContext.lookup(NamingContext.java:811)
>         at  
> org.apache.naming.NamingContext.lookup(NamingContext.java:194)
>         at com.pec.DBmultileague.testDB.init(testDB.java:30)
>
> java.sql.SQLException: Cannot load JDBC driver class 'null'
>         at  
> org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSourc 
> e.java:529)
>         at  
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.j 
> ava:312)
>         at com.pec.DBmultileague.testDB.init(testDB.java:30)
>
> Where the code looks like this (line 30 is the last presented here):
>       Context ctx = new InitialContext();
>       if(ctx == null )
>         throw new Exception("Boom - No Initial Context");
>
>       Context envCtx = (Context)ctx.lookup("java:comp/env");
>       if(envCtx == null )
>         throw new Exception("Boom - No Environmental Context");
>
>       DataSource ds =  
> (DataSource)envCtx.lookup("java:comp/env/jdbc/DBmultileague");
>
>
> I'm sure I'm close, and my server.xml and web.xml both seem to comply  
> to the rules. Is there something I need to do to have InitialContext  
> java:comp/env recognised?
>
> Thanks
> Paul
>
> FYI
> Tomcat 4.1.12
> Sybase 12.5
> MAC OSX 10.2.3
> jconn2.jar in place $CATALINA_HOME/common/lib (as well as the DBCP,  
> etc, jars)