By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,558 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,558 IT Pros & Developers. It's quick & easy.

java.sql.SQLException: No suitable driver when connecting to a DB2 database using driver COM.ibm.db2.jdbc.DB2XADataSource

P: n/a
Hi,

I want to get connection to a DB2 database using the driver
COM.ibm.db2.jdbc.DB2XADataSource. I have also included 'db2java.zip' in
the classpath. However I am getting the exception

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Conn.main(Conn.java:44)

The code that I am using (with try/catch removed) is as follows:
String url = "jdbc:db2:sample";
String driver = "COM.ibm.db2.jdbc.DB2XADataSource";
String dbuser = "db2user";
String dbpswd = "password";

Connection con = null;
if (url != null)
{
Class.forName(driver).newInstance();
if (dbuser == null || dbuser.length() == 0)
con = DriverManager.getConnection(url);
else
con = DriverManager.getConnection(url, dbuser, dbpswd);
}

I guess the url also is correct. Could anyone please let me know what
the problem is.

Thanks in advance,
Rakesh.

Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The Type 2 driver is:

COM.ibm.db2.jdbc.app.DB2Driver

Dario

Nov 12 '05 #2

P: n/a


Rakesh wrote:
Hi,

I want to get connection to a DB2 database using the driver
COM.ibm.db2.jdbc.DB2XADataSource. I have also included 'db2java.zip' in
the classpath. However I am getting the exception

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Conn.main(Conn.java:44)

The code that I am using (with try/catch removed) is as follows:
String url = "jdbc:db2:sample";
String driver = "COM.ibm.db2.jdbc.DB2XADataSource";
String dbuser = "db2user";
String dbpswd = "password";

Connection con = null;
if (url != null)
{
Class.forName(driver).newInstance();
Hi. The above line succeeded. This means the driver you mentioned
was found in the class path, and loaded.
if (dbuser == null || dbuser.length() == 0)
con = DriverManager.getConnection(url);
else
con = DriverManager.getConnection(url, dbuser, dbpswd);
}

I guess the url also is correct. Could anyone please let me know what
the problem is.
The exception you get means the URL is likely *not* correct. The driver manager
went through every driver registered with it (and if the driver you cited
is written correctly, it will have registered itself with the driver manager
while it was loaded above). No driver knew how to produce a connection
with your input.
Try this code:

java.sql.Driver d = (java.sql.Driver)Class.forName(driver).newInstance ();
(simply get an instance of the driver)
System.out.println(" Does this driver accept my URL? " + d.acceptsURL(url) );

Once you've solved the URL problem, if your application is
running in a multithreaded environment, I would strongly
advise that you avoid direct DriverManager calls, including
getConnection() because they are all class-synchronized, and
this can serialize all JDBC in the whole JVM.

Joe Weinstein at BEA Systems

Thanks in advance,
Rakesh.


Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.