I've currently got a fairly simple app running which has been using 
DriverManager.getConnection() in order to connect to a database.  I'd like 
to move this over to a JNDI-based DataSource solution; however, I'm having 
some problems, which I've seen have popped up for several people 
before.  Essentially, it seems that Tomcat never actually connects, or 
tries to connect, to the database; the DataSource returned by the Context's 
lookup() method is always null.

Code within the servlet:
         Context ctx = new InitialContext();
         Context envCtx = (Context) ctx.lookup("java:comp/env");
         DataSource ds = (DataSource)envCtx.lookup("jdbc/cw");
         Connection con = ds.getConnection();

The associated portion of server.xml is as follows:

<Resource name="jdbc/cw" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/cw">
         <parameter>
                 <name>driverClassName</name>
                 <value>com.sybase.jdbc2.jdbc.SybDataSource</value>
         </parameter>
         <parameter>
                 <name>user</name>
                 <value>dummy_user</value>
         </parameter>
         <parameter>
                 <name>password</name>
                 <value>dummy_passwd</value>
         </parameter>
         <parameter>
                 <name>driverName</name>
                 <value>jdbc:sybase:Tds:dbserv:2638</value>
         </parameter>
</ResourceParams>

I've put these two nodes both within a <Context> node and within a 
<DefaultContext> node, neither seemed to have any impact.

I've also tried this using the parameters listed in the docs for the 
SybDataSource class (serverName, portNumber, databaseName, networkProtocol) 
in various combinations, both with and without the driverName parameter; 
nothing seemed to have an effect.

The section in my web.xml file from the web application is:
<resource-ref>
         <res-ref-name>jdbc/cw</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
</resource-ref>

Now, I've examined the envCtx variable created in the code, and it does 
seem to have a binding for jdbc/cw to a javax.sql.DataSource at runtime, 
but that binding always returns null from a lookup.

I have a vague idea that the problem may be with the sybase JDBC drivers 
(jConnect V 5.5), but the documentation that comes with the drivers is 
surprisingly sparse on this subject, and I haven't been able to track down 
anyone else having similar problems connecting sybase to tomcat.  So, at 
this point, I'm not certain whether it's the JDBC driver, the JNDI config 
in server.xml, the webapp resource config in web.xml, or some other thing I 
haven't even thought of.

Any advice or input would be *greatly* appreciated!

cheers,

Keith



--
Keith O'Connell
4empowerment
[EMAIL PROTECTED]
512.528.0383


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to