• 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

No suitable Driver in DB2

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 36
Eclipse IDE Java ME Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
loganathan, please check your private messages.
 
loganathan kumar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 36
Eclipse IDE Java ME Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(driver:Driver);

See if this helps.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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(driver:Driver);


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?
 
Raj Chila
Ranch Hand
Posts: 128
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic