471,863 Members | 1,022 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

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

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
3 26883
The Type 2 driver is:

COM.ibm.db2.jdbc.app.DB2Driver

Dario

Nov 12 '05 #2


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.

Similar topics

2 posts views Thread by Kent Lewandowski | last post: by
8 posts views Thread by Rhino | last post: by
2 posts views Thread by dmstn | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.