You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rick Yoesting <ry...@mac.com> on 2002/09/03 22:25:44 UTC

Re: DB2 DataSources and Tomcat 4.0.4

Vance,


I did a little more digging and discovered that the JSP snippet I sent 
previously works using Class.forName() for both app and net drivers, but 
curiously enough Class.forName().newInstance() throws an SQLException 
when using the app driver, but not the net driver.

Using the app driver, our webapp throws the same SQLException (CLI0647E 
Error allocating DB2 environment handle, rc=-1) as the JSP snippet. So I 
took a peek at the Struts 1.0.2 GenericDataSource code, where the "Root 
Cause" SQLException originated and sure enough, there is a newInstance() 
call on the Driver. I'm not sure exactly what it means, and doubt it's 
even relevant to your situation, but it's interesting to note that two 
different implementations of DataSource appear to be failing in 
different ways (or perhaps we both doing something wrong!) using the app 
driver.

Concerning your question about what's more appropriate -- app or net 
driver?
According to IBM, for raw performance, the app driver is the one to use: 
http://www-1.ibm.com/support/docview.wss?rs=71&q=COM.ibm.db2.jdbc.net&uid=
swg21005576

Also, I don't think it's an XP issue, because we've not been able to get 
the app driver working on Linux either, except for explicit 
Class.forName() calls, which is why I suggested the net driver.

To me the upside of the net driver is two-fold:
1) it's more flexible -- allowing both local and remote connections (we 
actually need to do both)
2) we can actually get it to work via DataSource for local connections

I'm not a DB2 guru by any means and have never used the JNDI stuff in 
Tomcat, but I still suggest trying the net driver for 4.0.x, just to see 
if if works. We're  satisfied with it's performance, you might be too.

Of course, if you've got it working with 4.1.x, why don't you go ahead 
and use it?

Rick

On Friday, August 30, 2002, at 05:58 PM, Vance Christiaanse wrote:

> Rick,
>
> I tried the following (all with db2java.zip renamed to db2java.jar and
> located in lib\common):
>
> WORKED: The Class.forName code using the DB2 app driver with Tomcat 
> 4.0.4
> FAILED: DataSource using the DB2 app driver with Tomcat 4.0.4
> WORKED: DataSource using the Cloudscape driver with Tomcat 4.0.4
> WORKED: DataSource using the DB2 app driver with Tomcat 4.1.9 (and 
> 4.1.10)
>
> I certainly could have made some error in my testing. But I still 
> haven't
> heard anyone say they are successfully using the DB2 app driver to 
> implement
> a DataSource with Tomcat 4.0.4. It works just fine with 4.1.x.
>
> I'm doing all this on XP; I wonder if that's a factor.
>
> If DB2 is running on the same machine as Tomcat, wouldn't the app 
> driver be
> more appropriate--and faster? I don't know for sure but I would guess 
> there
> is more overhead with the net driver than the app driver when the 
> access is
> local. (When the access is non-local I realize the net driver is 
> necessary.)
>
> Vance
>
> ----- Original Message -----
> From: "Rick Yoesting" <ry...@mac.com>
> To: "Tomcat Users List" <to...@jakarta.apache.org>
> Sent: Friday, August 30, 2002 4:44 PM
> Subject: Re: DB2 DataSources and Tomcat 4.0.4
>
>
>> Vance,
>>
>> We're using DB2 via DataSource with Tomcat 4.0.3 using Struts
>> (<data-source> element in struts-config.xml), so I assume this means it
>> should work without Struts also. Below is a JSP snippet that should 
>> tell
>> you if you're driver is working or not outside of Tomcat's Resource
>> Factory.
>>
>>  From what I gathered in your previous posts, you're using
>> COM.ibm.db2.jdbc.app.DB2Driver. I think you should be using
>> COM.ibm.db2.jdbc.net.DB2Driver.
>>
>> As for where to put the driver -- we renamed the .zip file to .jar and
>> put it in <CATALINA_HOME>/common/lib.
>>
>> One last thought -- make sure DB2's JDBC Applet Server/Listener is
>> running.
>>
>> Good luck,
>>
>> Rick
>>
>> <%@ page language="java" import="java.util.*,java.sql.*" %>
>> <%
>> try {
>> Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
>>
>>
> DriverManager.getConnection("jdbc:db2://localhost/dbAlias","username","passw
> ord"
>> );
>>    Statement stmt = conn.createStatement();
>>
>>    ResultSet rs = stmt.executeQuery("select * from sometable");
>>
>> while (rs.next()) {
>> // do something
>> }
>>   rs.close();
>>   stmt.close();
>>   conn.close();
>>
>>   } catch (SQLException sqle) {
>>   // handle SQLException
>>   } catch (Exception e) {
>>   // handle exception
>>   }
>>   %>
>>
>> On Thursday, August 29, 2002, at 05:34 PM, Vance Christiaanse wrote:
>>
>>> Tomcat fans,
>>>
>>> I've been trying to configure a DataSource in Tomcat 4.0.4 to use DB2
>>> for...
>>> well, for longer than I'd like to admit. I've searched the web and
>>> experimented with jars vs. zips, with renaming them vs. rebuilding 
>>> them,
>>> with the lib folder vs. the common\lib folder, with "url" vs.
>>> "driverName",
>>> and so on.
>>>
>>> As a sanity check, I just tried switching my server.xml 
>>> driverClassName
>>> and
>>> driverName to values appropriate for Cloudscape and put the requisite
>>> jar
>>> files in common\lib. The DataSource in my servlet worked fine the 
>>> first
>>> time! (And for the first time ever!)
>>>
>>> I believe there is an issue with the DB2 driver involving native
>>> libraries
>>> and classloaders. I suspect that Tomcat works just fine with drivers
>>> (e.g.
>>> Cloudscape) that don't use native libraries.
>>>
>>> I'm sending this because I hope it
>>> (1) helps others who are trying to get DB2 working via a DataSource in
>>> Tomcat
>>> (2) inspires those who know more about this to tell us about it--
>>>     In particular, has *anyone* *ever* gotten this to work?
>>>
>>> Vance
>>>
>>>
>>> --
>>> To unsubscribe, e-mail:   <mailto:tomcat-user-
>>> unsubscribe@jakarta.apache.org>
>>> For additional commands, e-mail: <mailto:tomcat-user-
>>> help@jakarta.apache.org>
>>>
>>
>>
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>>
>>
>
>
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-
> help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DB2 DataSources and Tomcat 4.0.4

Posted by Vance Christiaanse <ci...@twcny.rr.com>.
Rick,

I think your results are relevant to my situation and I thank you very much
for trying the experiment. You are the first person to say what I've been
saying, which is

the DB2 app driver doesn't work with DataSources with Tomcat 4.0.4!

The 4.0.x DataSource code tries to do something (perhaps like your
experiment) that simply doesn't work with the DB2 app driver--although it
does work with most drivers, including the DB2 net driver and the Cloudscape
driver. I have even written some standalone code, separate from Tomcat
altogether, that generates the same errors I get with Tomcat by doing things
similar to your experiment with the app driver.

Here's my main goal:

I spent two days trying to get the DB2 app driver working with DataSources
and Tomcat 4.0.4. I believe it would have worked with the net
driver--although I'm not going to try that now because I've switched to
Tomcat 4.1.10. I know for sure it works with Cloudscape. I just want to put
something on the internet so that others who do a search for something like
"DB2 Tomcat DataSource" will find out that the app driver doesn't work with
4.0.4. I just don't want anyone else to go through what I did!

One solution: switch to Tomcat 4.1.x. 4.1.x uses different code to implement
DataSources and it works just fine with the DB2 app driver.

One more thing: yes, put db2java.jar (a rename of the JDBC 2.0 db2java.zip)
into %CATALINA_HOME%\common\lib.

Vance

----- Original Message -----
From: "Rick Yoesting" <ry...@mac.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, September 03, 2002 4:25 PM
Subject: Re: DB2 DataSources and Tomcat 4.0.4


> Vance,
>
>
> I did a little more digging and discovered that the JSP snippet I sent
> previously works using Class.forName() for both app and net drivers, but
> curiously enough Class.forName().newInstance() throws an SQLException
> when using the app driver, but not the net driver.
>
> Using the app driver, our webapp throws the same SQLException (CLI0647E
> Error allocating DB2 environment handle, rc=-1) as the JSP snippet. So I
> took a peek at the Struts 1.0.2 GenericDataSource code, where the "Root
> Cause" SQLException originated and sure enough, there is a newInstance()
> call on the Driver. I'm not sure exactly what it means, and doubt it's
> even relevant to your situation, but it's interesting to note that two
> different implementations of DataSource appear to be failing in
> different ways (or perhaps we both doing something wrong!) using the app
> driver.
>
> Concerning your question about what's more appropriate -- app or net
> driver?
> According to IBM, for raw performance, the app driver is the one to use:
> http://www-1.ibm.com/support/docview.wss?rs=71&q=COM.ibm.db2.jdbc.net&uid=
> swg21005576
>
> Also, I don't think it's an XP issue, because we've not been able to get
> the app driver working on Linux either, except for explicit
> Class.forName() calls, which is why I suggested the net driver.
>
> To me the upside of the net driver is two-fold:
> 1) it's more flexible -- allowing both local and remote connections (we
> actually need to do both)
> 2) we can actually get it to work via DataSource for local connections
>
> I'm not a DB2 guru by any means and have never used the JNDI stuff in
> Tomcat, but I still suggest trying the net driver for 4.0.x, just to see
> if if works. We're  satisfied with it's performance, you might be too.
>
> Of course, if you've got it working with 4.1.x, why don't you go ahead
> and use it?
>
> Rick
>
> On Friday, August 30, 2002, at 05:58 PM, Vance Christiaanse wrote:
>
> > Rick,
> >
> > I tried the following (all with db2java.zip renamed to db2java.jar and
> > located in lib\common):
> >
> > WORKED: The Class.forName code using the DB2 app driver with Tomcat
> > 4.0.4
> > FAILED: DataSource using the DB2 app driver with Tomcat 4.0.4
> > WORKED: DataSource using the Cloudscape driver with Tomcat 4.0.4
> > WORKED: DataSource using the DB2 app driver with Tomcat 4.1.9 (and
> > 4.1.10)
> >
> > I certainly could have made some error in my testing. But I still
> > haven't
> > heard anyone say they are successfully using the DB2 app driver to
> > implement
> > a DataSource with Tomcat 4.0.4. It works just fine with 4.1.x.
> >
> > I'm doing all this on XP; I wonder if that's a factor.
> >
> > If DB2 is running on the same machine as Tomcat, wouldn't the app
> > driver be
> > more appropriate--and faster? I don't know for sure but I would guess
> > there
> > is more overhead with the net driver than the app driver when the
> > access is
> > local. (When the access is non-local I realize the net driver is
> > necessary.)
> >
> > Vance
> >
> > ----- Original Message -----
> > From: "Rick Yoesting" <ry...@mac.com>
> > To: "Tomcat Users List" <to...@jakarta.apache.org>
> > Sent: Friday, August 30, 2002 4:44 PM
> > Subject: Re: DB2 DataSources and Tomcat 4.0.4
> >
> >
> >> Vance,
> >>
> >> We're using DB2 via DataSource with Tomcat 4.0.3 using Struts
> >> (<data-source> element in struts-config.xml), so I assume this means it
> >> should work without Struts also. Below is a JSP snippet that should
> >> tell
> >> you if you're driver is working or not outside of Tomcat's Resource
> >> Factory.
> >>
> >>  From what I gathered in your previous posts, you're using
> >> COM.ibm.db2.jdbc.app.DB2Driver. I think you should be using
> >> COM.ibm.db2.jdbc.net.DB2Driver.
> >>
> >> As for where to put the driver -- we renamed the .zip file to .jar and
> >> put it in <CATALINA_HOME>/common/lib.
> >>
> >> One last thought -- make sure DB2's JDBC Applet Server/Listener is
> >> running.
> >>
> >> Good luck,
> >>
> >> Rick
> >>
> >> <%@ page language="java" import="java.util.*,java.sql.*" %>
> >> <%
> >> try {
> >> Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
> >>
> >>
> >
DriverManager.getConnection("jdbc:db2://localhost/dbAlias","username","passw
> > ord"
> >> );
> >>    Statement stmt = conn.createStatement();
> >>
> >>    ResultSet rs = stmt.executeQuery("select * from sometable");
> >>
> >> while (rs.next()) {
> >> // do something
> >> }
> >>   rs.close();
> >>   stmt.close();
> >>   conn.close();
> >>
> >>   } catch (SQLException sqle) {
> >>   // handle SQLException
> >>   } catch (Exception e) {
> >>   // handle exception
> >>   }
> >>   %>
> >>
> >> On Thursday, August 29, 2002, at 05:34 PM, Vance Christiaanse wrote:
> >>
> >>> Tomcat fans,
> >>>
> >>> I've been trying to configure a DataSource in Tomcat 4.0.4 to use DB2
> >>> for...
> >>> well, for longer than I'd like to admit. I've searched the web and
> >>> experimented with jars vs. zips, with renaming them vs. rebuilding
> >>> them,
> >>> with the lib folder vs. the common\lib folder, with "url" vs.
> >>> "driverName",
> >>> and so on.
> >>>
> >>> As a sanity check, I just tried switching my server.xml
> >>> driverClassName
> >>> and
> >>> driverName to values appropriate for Cloudscape and put the requisite
> >>> jar
> >>> files in common\lib. The DataSource in my servlet worked fine the
> >>> first
> >>> time! (And for the first time ever!)
> >>>
> >>> I believe there is an issue with the DB2 driver involving native
> >>> libraries
> >>> and classloaders. I suspect that Tomcat works just fine with drivers
> >>> (e.g.
> >>> Cloudscape) that don't use native libraries.
> >>>
> >>> I'm sending this because I hope it
> >>> (1) helps others who are trying to get DB2 working via a DataSource in
> >>> Tomcat
> >>> (2) inspires those who know more about this to tell us about it--
> >>>     In particular, has *anyone* *ever* gotten this to work?
> >>>
> >>> Vance
> >>>
> >>>
> >>> --
> >>> To unsubscribe, e-mail:   <mailto:tomcat-user-
> >>> unsubscribe@jakarta.apache.org>
> >>> For additional commands, e-mail: <mailto:tomcat-user-
> >>> help@jakarta.apache.org>
> >>>
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >>
> >>
> >
> >
> > --
> > To unsubscribe, e-mail:   <mailto:tomcat-user-
> > unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:tomcat-user-
> > help@jakarta.apache.org>
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>