I am trying to connect to IBM mainfram db2 from java jdbc program.
I have db2jcc.jar,db2jcc_license_cisuz.jar and db2java.zip in classpath.
Here's the code
{code}public class DB2Connection {
public Connection connection = null;
public ResultSet resultset = null;
public Statement statement = null;
public void connect()
{
String url = "jdbc:db2://localhost:50000/MyData";
String uname = "user";
String psswrd = "pass";
try{
//Type 4 Driver
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
System.out.println("Driver Loaded Successfully ...");
}
catch(ClassNotFoundException e){
System.err.println("Could not load DB2 driver \n");
System.err.println(e.getMessage());
System.exit(1);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try{
connection = DriverManager.getConnection(url,uname,psswrd);
if (connection == null)
{
System.out.println("connection failed");
}
System.out.println("Successfully Connected to DB2...");
resultset.close();
statement.close();
connection.close();
}
catch(DisconnectException de){
System.out.println(" Exception: ");
System.err.println(de.getMessage());
}
catch (SQLException e){
System.out.println("SQL Exception: ");
System.err.println(e.getMessage());
}
}
public static void main(String[] args) throws Exception {
DB2Connection db2 = new DB2Connection();
db2.connect();
}
}
{code}
please help me with this.
Any help is highly appreciated.
thanks in advancd.