java.sql.SQLException: No suitable driver - COM.ibm.db2.jdbc.app.DB2Driver

Viewed 305

I am trying to connect to database using DB2JDBC Type 2 driver. Below is my java code

try
{
    
    String urlPrefix = "jdbc:db2:";
     String url = urlPrefix + paramString1;
       String user = paramString2;
        String password = paramString3;
        
  log.debug(context, 1010, "Connecting to : " + paramString1);
  
  Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
  localConnection = DriverManager.getConnection(url, user, password);
  localConnection.setAutoCommit(false);
  

I have added db2java.zip to my calss path and db2jdbc.dll is available in C:\Program Files (x86)\IBM\SQLLIB\BIN(Prior to this error I faced db2jdbc.dll not found error)

enter image description here

When I run my code am getting java.sql.SQLException: No suitable driver exception. What am I missing. Should I check the versions of the driver I have downloaded.

2 Answers

DB2 JDBC Type 2 Driver is discontinued since Db2 10.1.

Resolution

Use the IBM Data Server Driver for JDBC and SQLJ instead of the DB2 JDBC Type 2 Driver. Refer to the task Upgrading database applications and subtask Upgrading Java applications that use DB2 JDBC Type 2 driver.

If you use the DB2 JDBC Type 2 Driver to compile your Java applications or routines, you will receive an error as the driver cannot be found.

Java package names are class sensitive. The "COM" needs to be in lowercase:

Class.forName("com.ibm.db2.jdbc.app.DB2Driver").newInstance();
// Here--------^
Related