gdlp2004
asked on
ClassNotFoundException: com.ibm.as400.access.AS400JDBCDriver
Hello,
We are running into a strange issue when trying to run this class named Test. We are using a program called Optimal J, and when we execute this class inside of Optimal J it works perfectly. When we try to execute this class using java Test it does not work.
We ran java -cp . Test and this was the output:
ClassNotFoundException: com.ibm.as400.access.AS400 JDBCDriver
Exception in thread "main" java.lang.NullPointerExcep tion
at Test.main(Test.java:83)
The classpath is as follows:
C:\Sun\AppServer\jdk\jre\l ib\ext
The path to the driver is:
C:\Sun\AppServer\jdk\jre\l ib\ext\jt4 00.jar
We are running Windows XP Professional.
Any help would be greatly appreciated thanks.
Line 83 is commented below.
__________________________ __________ __________ __________ __________ __________ __________ __________ _____
// this line is used for the IDE but we comment it out when we use javac
package com.gdlp.sales.application .ejb;
import java.rmi.*;
import javax.rmi.*;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import javax.naming.*;
import javax.transaction.*;
import javax.sql.*;
import java.lang.*;
public class Test
{
public static void main(String[] args)
{
// connection to DB2
Connection db2 = null;
try
{
/*driver*/ Class.forName("com.ibm.as4 00.access. AS400JDBCD river");
db2 = DriverManager.getConnectio n(
/*url*/ "jdbc:as400:xxxx;translate binary=true;libraries=xxxx xxxx",
/*username*/ "xxxxx",
/*password*/ "xxxxxx");
}
catch(SQLException e)
{
System.out.println("DB2 Connect String SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "\t");
}
catch(ClassNotFoundExcepti on e){
System.out.println("ClassN otFoundExc eption: " + e.getMessage() + "\t");
}
// code to pull the customer info from DB2
PreparedStatement prepare = null;
ResultSet result = null;
ArrayList returnValue = new ArrayList();
String name = "";
try {
String custLoadQuery =
"select guioo from a767000a";
prepare = db2.prepareStatement(custL oadQuery, ResultSet.TYPE_SCROLL_INSE NSITIVE, ResultSet.CONCUR_READ_ONLY );
result = prepare.executeQuery();
while (result.next())
{
name = result.getString("guioo"). trim();
returnValue.add(name);
}
result.close();
System.out.println("Test\t Closed the resultset\n");
prepare.close();
System.out.println("Test\t Closed the prepared statement\n");
} catch (SQLException e) {
System.out.println("DB2 SQLException: " + e.getMessage() + "\t");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
} finally
{
try{
! LINE 83 ! db2.close(); <<<<<<<<<<<<<<<<<<<<<< ! LINE 83 !
}catch (SQLException e)
{
System.out.println("Close DB2 SQLException: " + e.getMessage() + "\t");
}
System.out.println("Test\t Closed the connection statement\n");
}
// end of DB2 Code
/*------------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---*/
// connection to oracle
Connection oracle = null;
try
{
/*driver*/ Class.forName("oracle.jdbc .driver.Or acleDriver ");
oracle = DriverManager.getConnectio n(
/*url*/ "jdbc:oracle:thin:@xxxxxxx :####:xxxx xxx",
/*username*/ "everestuser",
/*password*/ "everest");
}
catch(SQLException e)
{
System.out.println("Ora Connect String SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
}
catch(ClassNotFoundExcepti on e){
System.out.println("ClassN otFoundExc eption: " + e.getMessage() + "\t");}
// code to write the customer info to Oracle
PreparedStatement prepare2 = null;
ResultSet result2 = null;
String name2 = "";
try {
for(int i=0; i<returnValue.size(); i++)
{
System.out.println(i);
name2 = (String) returnValue.get(i);
System.out.println("Name : " + name2) ;
String custAddQuery =
"insert into admin (id,uniqueid,adminfname) values(admin_sequence.next val,admin_ sequence.n extval,'"+ name2+"')" ;
prepare2 = oracle.prepareStatement(cu stAddQuery , ResultSet.TYPE_SCROLL_INSE NSITIVE, ResultSet.CONCUR_READ_ONLY );
result2 = prepare2.executeQuery();
result2.close();
System.out.println("Test\t Closed the resultset\n");
prepare2.close();
System.out.println("Test\t Closed the prepared statement\n");
}
} catch (SQLException e) {
System.out.println("Oracle SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe ssage() + "<BR>");
} finally
{
try{
oracle.close();
}catch (SQLException e)
{
System.out.println("Close Oracle SQLException: " + e.getMessage() + "<BR>");
}
System.out.println("Test\t Closed the connection statement\n");
}
System.exit(0);
} // end of main class
} // end of entire class
We are running into a strange issue when trying to run this class named Test. We are using a program called Optimal J, and when we execute this class inside of Optimal J it works perfectly. When we try to execute this class using java Test it does not work.
We ran java -cp . Test and this was the output:
ClassNotFoundException: com.ibm.as400.access.AS400
Exception in thread "main" java.lang.NullPointerExcep
at Test.main(Test.java:83)
The classpath is as follows:
C:\Sun\AppServer\jdk\jre\l
The path to the driver is:
C:\Sun\AppServer\jdk\jre\l
We are running Windows XP Professional.
Any help would be greatly appreciated thanks.
Line 83 is commented below.
__________________________
// this line is used for the IDE but we comment it out when we use javac
package com.gdlp.sales.application
import java.rmi.*;
import javax.rmi.*;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.Date;
import javax.naming.*;
import javax.transaction.*;
import javax.sql.*;
import java.lang.*;
public class Test
{
public static void main(String[] args)
{
// connection to DB2
Connection db2 = null;
try
{
/*driver*/ Class.forName("com.ibm.as4
db2 = DriverManager.getConnectio
/*url*/ "jdbc:as400:xxxx;translate
/*username*/ "xxxxx",
/*password*/ "xxxxxx");
}
catch(SQLException e)
{
System.out.println("DB2 Connect String SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
catch(ClassNotFoundExcepti
System.out.println("ClassN
}
// code to pull the customer info from DB2
PreparedStatement prepare = null;
ResultSet result = null;
ArrayList returnValue = new ArrayList();
String name = "";
try {
String custLoadQuery =
"select guioo from a767000a";
prepare = db2.prepareStatement(custL
result = prepare.executeQuery();
while (result.next())
{
name = result.getString("guioo").
returnValue.add(name);
}
result.close();
System.out.println("Test\t
prepare.close();
System.out.println("Test\t
} catch (SQLException e) {
System.out.println("DB2 SQLException: " + e.getMessage() + "\t");
while((e = e.getNextException()) != null)
System.out.println(e.getMe
} finally
{
try{
! LINE 83 ! db2.close(); <<<<<<<<<<<<<<<<<<<<<< ! LINE 83 !
}catch (SQLException e)
{
System.out.println("Close DB2 SQLException: " + e.getMessage() + "\t");
}
System.out.println("Test\t
}
// end of DB2 Code
/*------------------------
// connection to oracle
Connection oracle = null;
try
{
/*driver*/ Class.forName("oracle.jdbc
oracle = DriverManager.getConnectio
/*url*/ "jdbc:oracle:thin:@xxxxxxx
/*username*/ "everestuser",
/*password*/ "everest");
}
catch(SQLException e)
{
System.out.println("Ora Connect String SQLException: " + e.getMessage() + "<BR>");
while((e = e.getNextException()) != null)
System.out.println(e.getMe
}
catch(ClassNotFoundExcepti
System.out.println("ClassN
// code to write the customer info to Oracle
PreparedStatement prepare2 = null;
ResultSet result2 = null;
String name2 = "";
try {
for(int i=0; i<returnValue.size(); i++)
{
System.out.println(i);
name2 = (String) returnValue.get(i);
System.out.println("Name : " + name2) ;
String custAddQuery =
"insert into admin (id,uniqueid,adminfname) values(admin_sequence.next
prepare2 = oracle.prepareStatement(cu
result2 = prepare2.executeQuery();
result2.close();
System.out.println("Test\t
prepare2.close();
System.out.println("Test\t
}
} catch (SQLException e) {
System.out.println("Oracle
while((e = e.getNextException()) != null)
System.out.println(e.getMe
} finally
{
try{
oracle.close();
}catch (SQLException e)
{
System.out.println("Close Oracle SQLException: " + e.getMessage() + "<BR>");
}
System.out.println("Test\t
}
System.exit(0);
} // end of main class
} // end of entire class
ASKER
CEHJ,
I'll try that and let you know what happens.
Thanks
I'll try that and let you know what happens.
Thanks
ASKER
CEHJ
I tired running that Props class you gave me and I get a NoSuchClassDef error, but it worked in OptimalJ because OptimalJ has it's own CLASSPATH.
I tired running that Props class you gave me and I get a NoSuchClassDef error, but it worked in OptimalJ because OptimalJ has it's own CLASSPATH.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
CEHJ
That seemed to do the trick now it works on my local machine. Thanks!!!
That seemed to do the trick now it works on my local machine. Thanks!!!
public class Props {
/**
* The main program for the Props class
*
* @param args The command line arguments
*/
public static void main(String[] args) {
if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
System.out.println(System.
}
}
else {
System.getProperties().lis
}
}
}