Solved

db2, jdbc, linux, no suitable driver

Posted on 2003-12-08
18
3,383 Views
Last Modified: 2007-12-19
We have a java program that calls db2 on our solaris/unix server.  If I login as user1 and run it it works, but if I login as user2 and try to run it, it throws a "No Suitable Driver" error. So it looks like a classpath issue, BUT i am able to compile the code under both logins just fine which means it is able to find the db2 db2java.zip driver, right?

Now we need to move the program over to redhat linux enterprise, again i setup the classpath etc.. and it compiles fine but when i try to run it I get the same "No Suitable Driver" error.

The Class.forName path is"COM.ibm.db2.jdbc.app.DB2Driver";  I am almost 100% certain this is not the issue and dont want to change it unless it will fix the problem.  

I am a bit unsure where to begin now to fix this problem, the driver is in the classpath after all and the class.forname is correct. What else could be causing this error?  

Thank you,

gaga
0
Comment
Question by:gagaliya
  • 9
  • 7
  • 2
18 Comments
 
LVL 1

Author Comment

by:gagaliya
ID: 9896842
o i dont care about solaris, as long as it will work on our new linux server everything is good.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9896849
 You load the driver dynamically so you might compile it perfectly but have problems on loading it.

> The Class.forName path is"COM.ibm.db2.jdbc.app.DB2Driver";  I am

  Can you make sure this is in your classpath? What happens if you do an echo $CLASSPATH ? You should be able to see the jar file or the top level directory of the above class.
0
 
LVL 35

Expert Comment

by:girionis
ID: 9896863
 Avtually the no suitable driver means that the driver can (probably) be found but there is a problem loading it. Can you post some source code where you try to load the driver?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9896874
Make sure you have permissions on the driver jar or what contains the class you're loading dynamically and that it's in your classpath.

It won't use the class until runtime
0
 
LVL 35

Expert Comment

by:girionis
ID: 9896890
 Take a look here:

http://java.sun.com/products/jdbc/faq.html

11. What causes the "No suitable driver" error?

"No suitable driver" is an error that usually occurs during a call to the DriverManager.getConnection method. The cause can be failing to load the appropriate JDBC drivers before calling the getConnection method, or it can be specifying an invalid JDBC URL--one that isn't recognized by your JDBC driver. Your best bet is to check the documentation for your JDBC driver or contact your JDBC driver vendor if you suspect that the URL you are specifying is not being recognized by your JDBC driver.

In addition, when you are using the JDBC-ODBC Bridge, this error can occur if one or more the the shared libraries needed by the Bridge cannot be loaded. If you think this is the cause, check your configuration to be sure that the shared libraries are accessible to the Bridge.
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9897193
Looks like I do have read permission on the driver files, that's all I need right? and those files are located under /opt/correctpath/java/

-r--r--r--    db2java.zip
-r--r--r--    runtime.zip
-r--r--r--    sqlj.zip

$ echo $CLASSPATH
:.:/opt/correctpath/java/runtime.zip:/opt/correctpath/java/db2java.zip:/opt/correctpath/java/sqlj.zip: etc..etc..

-----------------
private static String db2Driver = "COM.ibm.db2.jdbc.app.DB2Driver";
....................
Class.forName(db2Driver);  
db2URL = "jdbc:db2:" + nameofdbserver;
.................
con = DriverManager.getConnection(db2URL, user, pw);
.................
0
 
LVL 35

Expert Comment

by:girionis
ID: 9897469
> db2URL = "jdbc:db2:" + nameofdbserver;

  Can you check that the above has a correct syntax?
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9897628
yes the db url is correct, i had debug on which showed me its exact name, which is a constant.
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9897776
could different versions of db2java.zip be the problem? I tried a few different ones, all gave me no suitable driver error except one which said:

Exception in thread "main" java.lang.NoSuchFieldError: numBytesRead
        at COM.ibm.db2.jdbc.app.DB2Driver.SQLAllocEnv(Native Method)
        at COM.ibm.db2.jdbc.app.DB2Driver.<init>(DB2Driver.java:234)
        at COM.ibm.db2.jdbc.app.DB2Driver.<clinit>(DB2Driver.java:119)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:120)


Also i run the java program using java -cp "classpath" nameofprogram.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:girionis
ID: 9898140
 Infering from the above error message you probably use the right version of the drive. I am prety stumped right now. Can you make sure that no other zip file contain the driver you are trying to use? There might be a conflict. Also can you make sure that the driver is indeed in one of the zip files?
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9898210
hey are you saying the

Exception in thread "main" java.lang.NoSuchFieldError: numBytesRead

is the right driver? or the others which gave me no suitable driver is the right ones?

All i need to do in general to run the program is to make sure $CLASSPATH is set to include the db2 driver right.

thanks again,

gaga
0
 
LVL 35

Expert Comment

by:girionis
ID: 9899018
 The way things are neither drive is correct I guess. The NoSuchFieldError means that you are trying to access a field that does not exist due to using an older/earlier vesion of the class.

> All i need to do in general to run the program is to make sure $CLASSPATH is set to
>include the db2 driver right.

  Yes this is correct. Do something else. Use the old driver (the one that throws the No Suitable Driver error) and post the exact error message and the exact line the error occurs.
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9899339
SQL Exception:No suitable driver
java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getConnection(DriverManager.java:537)
        at java.sql.DriverManager.getConnection(DriverManager.java:177)
               ........

it stops at the line: con = DriverManager.getConnection(db2URL, user, pw);

I also tried removing the -cp part(which contains the classpath to the db2 driver db2java.zip etc) in

java -cp "classpath" programname

and got  ClassNotFoundException: COM.ibm.db2.jdbc.app.DB2Driver

So apparently it is finding/using the db2 driver in my classpath but somehow not loading the driver. I also unzipped db2java.zip and the path in there matchs the COM.ibm.db2.jdbc.app exactly and tehre is DB2Driver.class among a set of classes in it.

god this is frustrating:)

thanks again,

gaga
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9900383
0
 
LVL 35

Accepted Solution

by:
girionis earned 200 total points
ID: 9902451
> it stops at the line: con = DriverManager.getConnection(db2URL, user, pw);

  So the problem is not when it's loading the class but when it's trying to access the database. Can you make sure that the user has privileges to access the database?
0
 
LVL 35

Expert Comment

by:girionis
ID: 9902455
 Can you access the database using a standalone client with that user?
0
 
LVL 1

Author Comment

by:gagaliya
ID: 9904647
It turns out to access db2 i need to run the db2profile first which i guess sets up some environment settings. In unix it is automatically ran in the profile on startup and somehow on linux it is not, and that's what is causing the no suitable driver errors. I manually ran the db2profile script then tried my program and it worked like a charm.

Thank you all every much for your help.

gaga
0
 
LVL 35

Expert Comment

by:girionis
ID: 9904728
 Thank you... glad I helped :)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now