I am getting a ClassNotFoundException on the DB2 native driver and can not for the life of me figure out why. If you are familiar with running Java programs on an iSeries (AS400), not in WebSphere AS but in QShell, I sure wish you would help. Below you will find my environment variable setting for classpath (WRKENVVAR), followed by the QShell display echoing the classpath and running the java program "JavaApp1". After that the Java program is listed.
Thanks, Reed Peters
--------------------------------
Environment Variable CLASSPATH
--------------------------------
Display Environment Var (*JOB)
Name . . . . . . . . . : CLASSPATH
Value . . . . . . . . . : '.:/QIBM/ProdData/Java400/:/QIBM/ProdData/OS400/Java400/ext/jdbc2_0-stdext.jar:/QIBM/ProdData/OS400/Java400/ext/db2_classes.jar'
------------------------------
QShell Display - Showing error
------------------------------
STRQSH
$
echo $CLASSPATH
.:/QIBM/ProdData/Java400/:/QIBM/ProdData/OS400/Java400/ext/jdbc2_0-stdext.jar:/QIBM/ProdData/OS400/Java400/ext/db2_classes.jar
$
java JavaApp1
Pgm Version: C
Statement: Class.forName(com.ibm.db2.jdbc.app.DB2Driver)
Exception occured Step 1!
Message: com/ibm/db2/jdbc/app/DB2Driver
java.lang.ClassNotFoundException: com/ibm/db2/jdbc/app/DB2Driver java/lang/Throwable.<init>(Ljava/lang/String
V+4 (Throwable.java:90)
java/lang/Exception.<init>(Ljava/lang/String
V+1 (Exception.java:38)
java/lang/ClassNotFoundException.<init>(Ljava/lang/String
V+1 (ClassNotFoundException.java:65)
java/lang/Class.forName(Ljava/lang/String
Ljava/lang/Class;+5 (Class.java:121)
JavaApp1.main([Ljava/lang/String
V+18 (JavaApp1.java:21)
Statement: DriverManager.registerDriver(new com.ibm.db2.jdbc.app.DB2Driver())
java.lang.NoClassDefFoundError: com/ibm/db2/jdbc/app/DB2Driver java/lang/Throwable.<init>(Ljava/lang/String
V+4 (Throwable.java:90)
java/lang/Error.<init>(Ljava/lang/String
V+1 (Error.java:46)
java/lang/NoClassDefFoundError.<init>(Ljava/lang/String
V+1 (NoClassDefFoundError.java:43)
JavaApp1.main([Ljava/lang/String
V+73 (JavaApp1.java:30)
$
---------------------------------
Java Code:
---------------------------------
public class JavaApp1 {
public static void main(String[] args) {
Connection con = null;
System.out.println("Pgm Version: C");
System.out.println("Statement: Class.forName(com.ibm.db2.jdbc.app.DB2Driver)");
try {
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
} catch (Exception e) {
System.out.println("Exception occured Step 1!");
System.out.println("Message: " + e.getMessage());
e.printStackTrace();
}
System.out.println("Statement: DriverManager.registerDriver(new com.ibm.db2.jdbc.app.DB2Driver())");
try {
DriverManager.registerDriver(new com.ibm.db2.jdbc.app.DB2Driver());
} catch (Exception e) {
System.out.println("Exception occured Step 2!");
System.out.println("Message: " + e.getMessage());
e.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc
b2://localhost", "user", "password");
} catch (Exception e) {
System.out.println("Exception occured Step 3!");
System.out.println("Message: " + e.getMessage());
e.printStackTrace();
}
try {
if (con instanceof com.ibm.db2.jdbc.app.DB2Connection)
System.out.println("con is running under the native JDBC driver.");
} catch (Exception e) {
System.out.println("Exception occured Step 4!");
System.out.println("Message: " + e.getMessage());
e.printStackTrace();
}
try {
con.close();
} catch (Exception e) {
System.out.println("Exception occured Step 5!");
System.out.println("Message: " + e.getMessage());
e.printStackTrace();
}
}
}