f



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.

0
Rakesh
9/23/2005 9:02:50 AM
comp.databases.ibm-db2 12448 articles. 3 followers. arunrocks (9) is leader. Post Follow

3 Replies
1259 Views

Similar Articles

[PageSpeed] 6

The Type 2 driver is:

COM.ibm.db2.jdbc.app.DB2Driver

Dario

0
Dario
9/23/2005 10:24:42 AM
http://www-128.ibm.com/developerworks/db2/library/techarticle/dm-0402kitchlu/

0
Dario
9/23/2005 10:26:18 AM

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.
> 

0
Joe
9/23/2005 4:18:11 PM
Reply: