the following code runs fine in RAD 6.0 but after I export the the .class files into an executable JAR file and try to run it with a batch file it throws a couple errors.
the first error is caught when it can't read the external file and the appropriate prompt is displayed(that part is commented out at the moment). the file I'm accessing is locted in a folder in the project and named sysconfig.conf
second, to make sure it was the file that was not being read I put a sysout in the code that returned a null. then I hard coded the values into the class to make sure that was all it was, and it was not.
I think the executable JAR is not reading the db2j.jar that it needs for recognizing the DB2 driver. Can anyone help with this???
public abstract class JDBC_ConnectionManager {
private static
String DRIVER = "com.ibm.db2j.jdbc.DB2jDriver";
private static String URL = "jdbc
b2j:c:/cloudscapeLightingDatabases/lightingDB";
private static boolean SPECIFY_DATABASE_CREDENTIALS = false;
private static String USERID;// = "db2admin";
private static String PASSWORD;// = "db2admin";
private static Connection conn = null;
public static Statement stmt =
null;
public static void readFile() throws IOException {
FileReader file = new FileReader("../lighting/config/sysconfig.conf");
BufferedReader buffer = new BufferedReader(file);
String record = null;
ArrayList array = new ArrayList();
int i = 0;
try {
while ((record = buffer.readLine()) != null ) {
if((record.substring(0,2)).equalsIgnoreCase("//")){
continue;
}else{
array.add(record);
}
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
DRIVER = (String)array.get(0);
URL = (String)array.get(1);
String temp = (String)array.get(2);
USERID = (String)array.get(3);
PASSWORD = (String)array.get(4);
if(temp.equalsIgnoreCase("false")){
SPECIFY_DATABASE_CREDENTIALS = false;
}else{
SPECIFY_DATABASE_CREDENTIALS = true;
}
}
public static Connection getConnection() throws SQLException {
_/*try {
readFile();
} catch (IOException e1) {
JOptionPane.showMessageDialog(
new JFrame(),
"There was an error reading your file",
"Error",
JOptionPane.PLAIN_MESSAGE);
}
*/
try {
System.out.println(DRIVER);
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
throw new
RuntimeException(
"Unable to load
JDBC Driver: " + e.toString());
}
Connection conn = null;
if (SPECIFY_DATABASE_CREDENTIALS) {
conn =
DriverManager.getConnection(
URL,
USERID,
PASSWORD);
stmt =
conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
} else {
conn = DriverManager.getConnection(URL);
stmt =
conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
}
return conn;
}
}
Manifest file:
Manifest-Version: 1.0
Main-Class: ui.Init
Class-Path: db2j.jar
batch file:
@echo off
echo Executing files
start
java -classpath db2j.jar
start java.exe -jar lighting.jar manifest.mf Init.class
Here is the sysout and the error I get when I run the app using the batch file
com.ibm.db2j.jdbc.DB2jDriver
Exception in
thread "main" java.lang.RuntimeException: Unable to load JDBC Drive
r: java.lang.ClassNotFoundException: com.ibm.db2j.jdbc.DB2jDriver
at dataAccess.JDBC_ConnectionManager.getConnection(JDBC_ConnectionManage
r.java:84)