We help IT Professionals succeed at work.

No Suitable Driver Found

elkhawajah
elkhawajah asked
on
Hi Experts ..

I have the following code
// load the DB2 Driver
Class class1 = Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
//Db data = new Db();
// Get the connection with authentication
Connection connection = DriverManager.getConnection(url, user,
password);

// Disable auto-commit mode
connection.setAutoCommit(false);

return connection;

Open in new window


I am getting this error:
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.ibm.lims.databaseobject.impl.BaseDAO.getConnection(BaseDAO.java:82)
... 20 more

Open in new window

I have db2java.jar in my eclipse project build path.

What else should I do to make it work?
Thx!
Comment
Watch Question

Top Expert 2016

Commented:
Does the below statement compile?
COM.ibm.db2.jdbc.app.DB2Driver driver = null;

Open in new window

Author

Commented:
Yes.

Author

Commented:
I've just upgrade eclipse JRE version from 1.5 to 1.6 and it works!
but I got another error:

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.ibm.db2.jcc.am.vo: [jcc][10165][10045][4.8.87] Invalid database URL syntax: jdbc:db2://localhost:50000;DatabaseName=sample;. ERRORCODE=-4461, SQLSTATE=42815
    at com.ibm.db2.jcc.am.gd.a(gd.java:676)
    at com.ibm.db2.jcc.am.gd.a(gd.java:60)
    at com.ibm.db2.jcc.am.gd.a(gd.java:85)
    at com.ibm.db2.jcc.DB2Driver.tokenizeOptionalPortNumber(DB2Driver.java:830)
    at com.ibm.db2.jcc.DB2Driver.connect(DB2Driver.java:381)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at com.ibm.lims.databaseobject.impl.BaseDAO.getConnection(BaseDAO.java:83)
    ... 20 more
Caused by: java.util.NoSuchElementException
    at java.util.StringTokenizer.nextToken(Unknown Source)
    at java.util.StringTokenizer.nextToken(Unknown Source)
    at com.ibm.db2.jcc.DB2Driver.tokenizeOptionalPortNumber(DB2Driver.java:809)
    ... 24 more

Top Expert 2016
Commented:
Looks like the connection string is wrong

Author

Commented:
Thank you, I have modified connection string and it works.

Another question, how can I modify db2java.jar to work with java 1.5?
Top Expert 2016

Commented:
>>Thank you, I have modified connection string and it works.

Did you add a forward slash before the port number by any chance?

>>Another question, how can I modify db2java.jar to work with java 1.5?

After your changes, what happens now if you turn back to 1.5?

Author

Commented:
>> Did you add a forward slash before the port number by any chance?

I changed connection string from jdbc:db2://localhost:50000;DatabaseName=sample
to jdbc:db2://localhost:50000/sample

>> After your changes, what happens now if you turn back to 1.5?
I get No Suitable Driver Found error
You'll have to find an older version of the driver that is 1.5 compatible.  From the error messages you're getting, it seems that the JAR you have is compiled against 1.6.

Author

Commented:
Thank you guys, I am splitting the points between both of you as I found the solution myself.
Top Expert 2016

Commented:
OK - glad you got it working. Personally i don't mind if you keep your points (accept your own answer)
Top Expert 2016

Commented:
:-)