my dog learned polymorphism*
The moose likes Tomcat and the fly likes problem in getting sybase Datasource in Tomcat 4.1.12 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "problem in getting sybase Datasource in Tomcat 4.1.12" Watch "problem in getting sybase Datasource in Tomcat 4.1.12" New topic

problem in getting sybase Datasource in Tomcat 4.1.12

giri pal

Joined: Nov 06, 2002
Posts: 3
Can any post sample code, that uses datasource (from sybase) in Tomcat 4.1.12.
I am having trouble in getting the connection from the data source. I have modified the server.xml, web.xml based on the documentation. but i am getting the following error:
java.sql.SQLException: Cannot load JDBC driver class 'null'
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSou
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
Here is what I did it in server.xml:
<Environment name="simpleValue" override="true" type="java.lang.Integer" value="30"/>
<Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" scope="Shareable" type="org.apache.catalina.UserDatabase"/>
<Resource name="jdbc/TestDB" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="UserDatabase">
<ResourceParams name="jdbc/TestDB">
and in web.xml:
<description>DB Connection</description>
and in my java class:
initContext = new InitialContext();
if(initContext == null )
throw new Exception("Boom - No Context");
envContext = (Context)initContext.lookup("java:comp/env");
ds = (DataSource)envContext.lookup("jdbc/TestDB");
if (ds != null) {

Connection conn = ds.getConnection();//i am getting exception here

if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
ResultSet rst =
"select coutn(*) from employee");
if( {
}catch(Exception e) {
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

When you put jdbc/TestDB into web.xml, you've just 'overwritten' the one you defined in server.xml.

Do one, but not both, and see if it works.
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
I am wondering why you are editing server.xml at all, instead of just web.xml for your application? Do you really need global configuration like that?
In my (admittedly limited) experience, it seems to me that you would want to configure just your application (in {CATLINA_HOME}/webapps/[your_app]/WEB-INF/web.xml) and put the JDBC drivers in {CATLINA_HOME}/webapps/[your_app]/WEB-INF/lib
This way, once you get it all working, you know that it is portable via a "war" file, and you won't have to mess around with the server on the deployment target.
For a default Tomcat installation, you can simply drop a "war" file into the webapps directory, and it gets automagically deployed for you.
I have Netbeans 3.4 on my workstation (with its bundled Tomcat server), and another Tomcat server identical in version and configuration (all default) to my deployment target. I don't put any jar files into JDK_HOME\jre\lib\ext on the workstation or the deployment target. Anything "extra" to my app goes into WEB-INF\lib.
Once the app is working in Netbeans, I use the built-in "deploy war file" feature to deploy to the other Tomcat server on my workstation... just to make sure it still works. When it passes that test, then I deploy to my actual server target. That server has both the J2SE and Tomcat installations in their default configurations.
This has been working quite well for me, so far.
[ November 06, 2002: Message edited by: Philip Shanks ]

Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
I agree. Here's the link:
subject: problem in getting sybase Datasource in Tomcat 4.1.12
Similar Threads
Datasource for Tomcat 4.1 and Sybase
Exception while connectiing DB through Tomcat
JNDI Connection with Oracle (Problem with NullPointerException)
Tomcat Database Connection Pooling Error
DBCP => Cannot create JDBC driver of class '' for connect URL 'null'