aspose file tools*
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
Author

problem in getting sybase Datasource in Tomcat 4.1.12

giri pal
Greenhorn

Joined: Nov 06, 2002
Posts: 3
HI,
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
rce.java:529)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource
.java:312)
Here is what I did it in server.xml:
GlobalNamingResources>
<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">
<parameter>
<name>factory</name>
<value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
</parameter>
<parameter>
<name>pathname</name>
<value>conf/tomcat-users.xml</value>
</parameter>
</ResourceParams>
<ResourceParams name="jdbc/TestDB">
<parameter>
<name>validationQuery</name>
<value></value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>2</value>
</parameter>
<parameter>
<name>password</name>
<value>xxxx</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:sybase:Tds:localhost:3000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.sybase.jdbc2.jdbc.SybDriver</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>username</name>
<value>xxxx</value>
</parameter>
</ResourceParams>
</GlobalNamingResources>
----------------------------------
and in web.xml:
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
--------------------------------------
and in my java class:
try{
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 =
stmt.executeQuery(
"select coutn(*) from employee");
if(rst.next()) {
foo=rst.getString(1);
//bar=rst.getInt(3);
}
conn.close();
}
}
}catch(Exception e) {
e.printStackTrace();
}
-----------------------------
Thanks
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.
PCS
[ 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!
 
 
subject: problem in getting sybase Datasource in Tomcat 4.1.12