Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to connect to mainframe db2

0 views
Skip to first unread message

nsu...@yahoo.com

unread,
Oct 6, 2008, 10:58:33 AM10/6/08
to
Hi,

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.

tonkuma

unread,
Oct 9, 2008, 6:25:02 PM10/9/08
to
What error messages did you get?
0 new messages