• 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

JSP DB2 Driver WebSphere

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to deploy a fairly simple JSP which accesses local data from a DB2 database. I'm using WebSphere 3.5.1. I'm using a straightforward tsx tag, as shown here:

Unfortunately, this throws an InvalidDBDriver Exception, like so:

Now, I am pretty sure that what is going on is that I do not have com.ibm.db2.jdbc.net.DB2Driver in my classpath; however, I'll be damned if I know which of the seemingly dozens of copies of db2java.zip I need to reference in my classpath, or if there is something else I need to do. Any clues?
Thanks, folks.
jk
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James ,
Looks like a classpath problem. what do you mean by


which of the seemingly dozens of copies of db2java.zip I need to reference in my classpath.


Just try unziping the db2java.zip. if there is only one jar file then see if it contains folders com/ibm/db2/jdbc/net/ by using a winzip utility. If it contains the driver then put this in your class path.
If it contains many jar files. then you have to search which one contains the "com/ibm/db2/jdbc/net/" folders and the driver and set this particular jar file in you classpath
Note: it is necessary that you specifically add the jar file in your classpath and not the folder only
ex if the directory c:\rahul contains your jar file by the name r.jar then your classpath must contain c:\rahul\r.jar. if you specify c:\rahul in the classpath you will still not have r.jar in the classpath.
Hope things work out.

------------------
Regds.
Mahindrakar
 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing i would like to add there in the driver syntax the com has to be in capital- COM.ibm.db2.jdbc.app.DB2Driver, make sure u have that ,and also the driver loaded in the classpath too, and first try with the app driver, it always works
 
James Kiley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, db2java.zip is in the classpath appropriately, and I tried stuffing the
darned file into a few other places, and still no dice. I've poked at various config
elements in the admin console, and nothing seems to change what's going on.
Here's the calling code:

And this is the error result that pops out from ErrorReporter, which just does a stack trace:

(... it goes on, but goes into the com.sun.jsp.runtime package, which isn't the problem here.)
Line 21 of my app is, of course, the one I have listed above, the tsx:dbconnection.
This says to me that the driver is failing to connect to the database, but that WAS is
finding and running the driver properly. Am I reading it right? If so, any suggestions
on fixing it? I have just about every conceivable DB2-o-centric service up and
running as I try this.
Thanks!
jk

[This message has been edited by James Kiley (edited February 26, 2001).]
 
daman sidhu
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am pasting the sample code which i use normally, if this doesnot work then there is some other problem, you should try to use the DataSource object then instead of this way.

Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Connection con=DriverManager.getConnection"jdbc:db2:mydb","userid","password");

FOr DataSource youll have to use JNDI, if u know how to go about it then well enough otherwise ill paste a sample of that too here.
Hope it works,
Regards,
Daman
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did it !! but how? (mine is an NT box)
replace d\:\websphere\appserver\lib\db2java.zip (~807 kb) with the db2\sqllib\db2java.zip(~1087 kb) and include in class path.
the follow with the usual stuff like..
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Somewhere I read that the driver classes coming with websphere is partial and that one with db2 is in full.. so i tried that way and it worked for me !!
cheers !
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could someone tell me where to set the class path? I couldn't find it... Thanks!
David
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
gaaggg
Welcome to Javaranch. We follow some conventions pertaining to User names. The rules are specified at here . These conventions are strictly followed. There are no Exceptions in this case. In the simplest of terms names are required to have at least two words separated by a space. It would be advised that this be your real full name.
Your User name does not follow these conventions. It is recommended that you immediately register under a name conforming to the conventions.
 
Rahul Mahindrakar
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the admin.config file located in your bin folder. You have to set the classpath in the classpath line.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Following code work fine when DB2 is on the same machine.
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Connection con=DriverManager.getConnection("jdbc:db2:TEST","user","password");
But When I tried to access the DB2 on different server
S0F104f:3456 (machinename ort)/DataBaseID as follows: i trid
IPADDRESS:3456/DATABASEID also
//Connection con=DriverManager.getConnection("jdbc:db2://S0F104f:3456/TEST","user","password");
//Connection con=DriverManager.getConnection("jdbc:db2://127.0.0.1:3456/TEST","user","password");

It fails:
Exception occured
java.sql.SQLException: No suitable driver
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at TestDB2.main(TestDB2.java:37)

Also please let me know i can use DataSource, connection
pooling for this. I want to Use this in Java Beans, and EJB Session Beans.
Thanks in advance
Ashish
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,
At the outset, I would like to say that I donot have any experience on IBM products.This analysis is based on my experience on Oracle Java products.
There are couple of reasons why you could be getting this error :

  • DB URL not correct - Confirm the listener port is OK.
  • Correct db2java.zip(~1087 kb instead of ~807 kb) should be on the DB2 machine classpath

  • As regards DataSource is concerned, your DB should support JDBC 2.0 features.Assuming that it does, it is just a question of doing a ctx.lookup() with a proper URL.As regards ConnectionPooling, if you are having the DataSource feature then it is taken care of implicitly.
    Hope this helps,
    Sandeep

 
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running into the same problem with WAS 4.0. If you are just doing a JDBC connection without the app server you can use the driver class COM.ibm.db2.jdbc.net.DB2Driver instead of COM.ibm.db2.jdbc.app.DB2Driver. IBM has documentation about this on their site. But I can't figure out how to specify the remote host for DB2 on WAS 4.0. Maybe this is something they aren't going to support until the multi-server is released?

Originally posted by Ashish Kejriwal:
Following code work fine when DB2 is on the same machine.
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
Connection con=DriverManager.getConnection("jdbc:db2:TEST","user","password");
But When I tried to access the DB2 on different server
S0F104f:3456 (machinename ort)/DataBaseID as follows: i trid
IPADDRESS:3456/DATABASEID also


 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may need to update the DB2 Drivers to JDBC 2.0 . On WinNT or Win2000 - In the <DB2 install Path>\SQLLIB\JAVA12 directory is a usejdbc2.bat.
You need to stop all DB2 Services and then run the bat file. This will copy the appropriate db2java.zip file to the \sqllib\java directory.
Restart the DB2 services and make sure that
"<install Path>\sqllib\java\db2java.zip "
is in the classpath.
If you are using Visual Age WebSphere Test Environment (WTE), you need to set the classpath in the WTE and\or the workspace for the WTE environment to find the driver.
--For workspace - Window|Options|Resources "Edit Workspace Classpath"
-- WTE has edit classpath button. Select All is safe and you can add additional paths if needed.
I'm not sure if this is the problem you are describing, but this is something that I struggled with for days. This should be of help to someone out there.
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I got from IBM:
"WebSphere 4.0 Trial/AEs was developed to work with all software on the Local system. It was designed not to use any remote services from other systems. Having said that, it is [in theory] possible to configure DB2 to use a remote server seamlessly by installing a local DB2 client. You will have to install
the DB2 client on the local system and then use the DB2 control center to link the two systems."
I was able to install the client, use the control center and get the data source working.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can access mine from the control center, but how can I access this database from a browser?
I tried using a JDBC driver but I keep on getting errors.
(my db is on OS390)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ashish,
I had exactly the same problem with WAS 5.0.2 connecting to a DB2 on OS390.
What I did? Obviously, I tried several changes, but were unsuccessfull all of them.
Finally, I just put the db2java.zip at the beginning of classpath, and that was it.
I hope this will help you. Good luck
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic