2
votes

I am trying to connect to the AS400 DB2 database using the JDBC in a java program but I am unable to connect as it is giving a SQLException stating No suitable driver found for ​jdbc:as400://192.168.1.11

Whereas I added No suitable driver found for ​jdbc:as400://192.168.1.11

I added the following libraries to my project: db2jcc_licence_cu.jar, db2jcc4.jar, jt400-6.4.jar.

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class ReadAllTables {
        public static void main(String args[]) throws Exception {
                //Class.forName ("com.ibm.as400.access.AS400JDBCDriver");
                DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());

                // Enable logging
                // DriverManager.setLogStream(System.err);

                System.out.println("Getting Connection");
                Connection c = DriverManager.getConnection ("​jdbc:as400://ipaddress","username","password");  
                DatabaseMetaData md = c.getMetaData();
                ResultSet rs = md.getTables(null, null, "%", null);
                while (rs.next()) {
                  System.out.println(rs.getString(3));

                }



        }

}

This is what the error I am getting:

Getting Connection Exception in thread "main" java.sql.SQLException: No suitable driver found for ​jdbc:as400://192.168.1.11 at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.test.ReadAllTables.main(ReadAllTables.java:18)

Thanks in advance

1
"No suitable driver found " means you don't have the AS/400 JDBC driver jar file on the classpath for your code. - Jim Garrison
I have jar files in the classpath but still getting this error. - Shahbaz Khan
Where in the classpath. If Tomcat needs to set up connection pooling the jar may need to go in Tomcat's jar directory, not your appliation's jar directory. - Jim Garrison
I have not created any web application or a project whereas I just wrote a java program to test the connection with the AS400 server db2 database. I added the jar files in environment variables classpath. - Shahbaz Khan
Please show how you run the program. A lot of ways of running Java programs don't use the CLASSPATH environment variable. - Mark Rotteveel

1 Answers

5
votes

You must have jt400.jar in your classpath for the AS/400 JDBC driver to work.

Version 7.10 is in Maven or download the latest from https://sourceforge.net/projects/jt400/ or copy it from IFS. The native CC driver is only used when running locally on the AS/400.

Given your current list of jars it sounds like your CLASSPATH variable is incorrect (or if you use a runnable jar, your Class-Path line in the manifest file is wrong). If you launch with RUNJVA the mechanism is different.