2

The below code is compiled successfully.

Code Source(Jdbcexample.java) and compiled class file (JdbcExample.class) directory:-"test" When I ran this program using java JdbcExample, it throws class not found com.ibm.as400.access.AS400JDBCDriver and in job log:

code ended with 04:Unable to find class required to run Java Program".

The problem is related to class path I suppose.

can anyone please guide me how should set path/classpath and run program to avoid above error?

import java.sql.*;  

public class JDBCexample {  
  public static void main(String[] args)
  {
    Connection con = null;  
    try {  
          Class.forName("com.ibm.as400.access.AS400JDBCDriver);  
        }
    catch(ClassNotFoundException e)
        {  
          System.out.println(e);  
          System.exit(0);  
        }  
    try {  
          con = DriverManager.getConnection("jdbc:as400://yourserver", "yourUserId","yourPassword");  

          Statement stmt = con.createStatement();  
          ResultSet rs = stmt.executeQuery("SELECT * FROM YOURLIB.YOUR_PF_FILE");  

          while (rs.next())
         {  

                  String field1 = rs.getString(1);  
                  String field2 = rs.getString("fieldname");  


          }
           rs.close();
           stmt.close();
           con.close();
       }
          catch(Exception e)
          {  

          }  

          }  
}
2

6 Answers 6

1

The error says it cannot find the JDBC driver. That driver is part of the IBM Toolkit for Java. In my case, I am using JTOpen instead of the version that ships with the machine. I put jt400.jar in the IFS in a directory called java.

If running from IBM i (not PASE or QShell), you set your classpath with ADDENVVAR. This works for me because I put my .jar files in /java:

ADDENVVAR ENVVAR(CLASSPATH) VALUE('.:+       
                                  /java:+   
                                  /java/*') 

The jt400 that is shipped with the machine is in the IFS. On my 7.2 machine, the path is: /QIBM/ProdData/HTTP/Public/jt400/lib - if you want to use that version, put that path in your CLASSPATH. IBM maintain a FAQ on the Toolbox.

Sign up to request clarification or add additional context in comments.

Comments

0

Set your classpath with the below command and execute your java program.

SET CLASSPATH=%DIR%\lib\yourlib.jar

Comments

0

Class.forName("com.ibm.as400.access.AS400JDBCDriver);

have you added the relevant jar for AS400JDBCDriver in your project.check it once

Comments

0

try

java -cp pathtojarlib:. JdbcExample

where pathtojarlib is the path of your connector library

Comments

0

I thought you have done some silly mistake. Please check your class name. IN the above given code the class name is JDBCexample and you use java JdbcExample to run .. Use java JDBCexample

Comments

0

Add classpath to your jar's MANIFEST.MF. Example:

Manifest-Version: 1.0
Main-Class: JdbcExample
Class-Path: lib/db2jcc.jar lib/commons-logging-1.1.3.jar

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.