• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in getting sybase Datasource in Tomcat 4.1.12

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
reply
    Bookmark Topic Watch Topic
  • New Topic