Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » connecting to DB2
connecting to DB2 [message #183630] Sun, 10 December 2006 02:59 Go to next message
Eclipse UserFriend
Originally posted by: tmmuralikrishnan.gmail.com

Hey pals.. im new to eclipse.. i want to get connected to database DB2..
please mention me the procedures or give me a sample code for connecting
to DB@
Re: connecting to DB2 [message #184277 is a reply to message #183630] Tue, 12 December 2006 18:57 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: chadboomershine.xxxxxxx.net

import java.sql.*;

class DB2Sample {
static {
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").newInstance();
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String argv[]) {
Connection con = null;

// URL is jdbc:db2:dbname
String url = "jdbc:db2:xxxxxx";

try {
if (argv.length == 0) {
// connect with default id/password
con = DriverManager.getConnection(url);
}
else if (argv.length == 2) {
String userid = argv[0];
String passwd = argv[1];
// connect with user-provided username and password
con = DriverManager.getConnection(url, userid, passwd);
}
else {
System.out.println("Usage: java DB2Sample [username
password]");
System.exit(0);
}
// retrieve data from the database
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery
("select * from ...");
System.out.println("Output:");
System.out.println(" ");
// display the result set
// rs.next() returns false when there are no more rows
while (rs.next()) {
String column1 = rs.getString("column1");
String column2 = rs.getString("column2");
System.out.println(" " + column1 + " " + column2);
}
rs.close();
stmt.close();
} catch( Exception e ) {
System.out.println(e);
}
}
}
Re: connecting to DB2 [message #184574 is a reply to message #183630] Fri, 15 December 2006 05:06 Go to previous message
Eclipse UserFriend
Originally posted by: tmmuralikrishnan.gmail.com

Thank u chad!!!
Previous Topic:News server
Next Topic:Help getting Eclipse running on Solaris
Goto Forum:
  


Current Time: Fri Apr 26 08:58:22 GMT 2024

Powered by FUDForum. Page generated in 0.08392 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top