aspose file tools*
The moose likes JDBC and the fly likes No suitable Driver in DB2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "No suitable Driver in DB2" Watch "No suitable Driver in DB2" New topic
Author

No suitable Driver in DB2

loganathan kumar
Greenhorn

Joined: Sep 22, 2008
Posts: 6
Hi,
I am working in UNIX.I tried to connect to DB2(client) which is in windows. when i tried to connect to DB2 from UNIX, it shows No suitable driver. If i connect from windows,it works fine.

Here is my code

import java.sql.*;

public class JdbcTest1 {

public static void main (String[] args) {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
String url = "jdbc:db2:dbname";
Connection conn = DriverManager.getConnection(url,username,password);
System.out.println("connection success");
} catch (Exception e) {
e.printStackTrace();
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}


Here is the error that i have got,


java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:189)
at JdbcTest1.main(JdbcTest1.java:18)


db2java.zip,db2jcc.jar are in my classpath.

kindly give me a solution.

Thanks in advance
[ September 22, 2008: Message edited by: loganathan ]
T.A. Nguyen
Ranch Hand

Joined: Sep 02, 2008
Posts: 36

No Suitable Driver, usually mean, that you don't have the correct url. The correct TCP/IP url should be like:
"jdbc:db2://host:port/database"

for remote connection. And you should use the com.ibm.db.jdbc.net.DB2Driver with it. Your com.ibm.db.jdbc.app.DB2Driver rely on the local connection and thus, the same code will not work on a remote machine, even with other Windows computer.

As of version 8, IBM moved to a unified driver you should use: com.ibm.db2.jcc.DB2Driver instead. Please check with IBM website for detail.


T.A. Nguyen
http://ta.cnci.org
http://www.linkedin.com/in/nguyenta
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

loganathan, please check your private messages.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
loganathan kumar
Greenhorn

Joined: Sep 22, 2008
Posts: 6
Thanks Nguyen,

But i need some detail explanation about the host and the port.
Host means my windows machine ip or DB2 server ip? and how to find the port?

Thanks
T.A. Nguyen
Ranch Hand

Joined: Sep 02, 2008
Posts: 36

As I said, please check with IBM driver installation and product for detail.

Originally posted by loganathan sadish:
Thanks Nguyen,

But i need some detail explanation about the host and the port.
Host means my windows machine ip or DB2 server ip? and how to find the port?

Thanks
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

I dont think entering wrong URL will report a "No Suitable Driver" error. Any Driver implementation will report that conveys a message "Cannot connect to Database".

In some cases, it might not be enough that you load a driver through Class.forName. you might have to explicitly call DriverManager.registerDriver(driverriver);

See if this helps.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
I dont think entering wrong URL will report a "No Suitable Driver" error.

Yes it will.

In some cases, it might not be enough that you load a driver through Class.forName. you might have to explicitly call DriverManager.registerDriver(driverriver);

The javadocs of the java.sql.Driver class explicitly state that a driver should register itself, so any such driver would be quite badly written. Have you encountered a driver where this was the case?


Ping & DNS - my free Android networking tools app
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

I did not know that. I assumed as long as the url pattern matches jdbc:db2: then it will pick the right Driver. Also because loganathan mentioned it was working in Windows and not in Linux, it is not possible that you have "\" issues in a URL...

But it looks like dbname in the code snippet does not resolve to any URL as such so in windows (as the DB2 is running locally on windows) the dbname must easily resolve to the type 2 driver connection.

Dittmer,

As far as my experience with registering the driver is concerned, I have seen this happening in HSQL, I was getting a No Suitable Driver exception and did not come accross it once I "registered" the Driver with the Driver manager. Also we could have faced this problem because we have different processes exlusively starting/stopping a centralized database.
[ September 28, 2008: Message edited by: Raj Chila ]
Ravi KumarHm
Greenhorn

Joined: Apr 22, 2010
Posts: 2
Me too facing the same issue. Even though I included db2java.jar file, it throws "No suitable driver" found exception. I am referring to local driver.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No suitable Driver in DB2