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)
{
}
}
}