Hi all,

I have a problem conneting to db2 database when I'm running my java program on Windows 98. I received "SQLException: Could not connect to database". But I don't have any problem if I use the Windows 2000 pro. Any suggestions and ideas could be great.

Thank you in advance.
Billy Lin

I installed the DB2 clients on both machine. I have the classpath on both the Windows98 and Windows2000Pro.

"CLASSPATH=.;C:\Program Files\SQLLIB\java\db2java.zip;C:\Program Files\SQLLIB\java\db2jcc.jar;C:\Program Files\SQLLIB\bin;C:\Program Files\SQLLIB\tools\db2XTrigger.jar;C:\Program Files\SQLLIB\java\common.jar;C:\Program Files\SQLLIB\java\db2jcc_license_cu.jar;"

My DB2 vervion is:

C:\>java -version
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)

* testdb2connection.java
* Created on March 16, 2004, 10:17 AM

import java.sql.*;

public class testdb2connection1 {

public static void main(String[] args) {
Connection con = null;
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").ne wInstance();
System.out.println("JDBC driver loaded");
String url = "jdbc:db2://";
String user = "myusername";
String password = "mypassword";
con = DriverManager.getConnection(url, user, password);
System.out.println("Database connection established");

}catch(ClassNotFoundException cnfe){
System.out.println("ClassNotFoundException: Could not locate driver");

}catch(SQLException cnfe){
System.out.println("SQLException: Could not connect to database");
}catch(Exception e){
System.out.println("An unknown error occurred while connecting to database");
if (con != null){
}catch(SQLException sqle){
System.out.println("Unable to close database connection.");