// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.sql.*;

public class DB2 {
    public static void main(String[] args) {
        try {
            Class.forName("com.ibm.db2.jcc.DB2Driver");
            Connection con = DriverManager.getConnection("jdbc:db2://localhost:50000/Test", "xxx", "xxx");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT x* FROM T1");
            while(rs.next()) {
                int f1 = rs.getInt(1);
                String f2 = rs.getString(2);
                System.out.println(f1 + " " + f2);
            }
            con.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println(e.getErrorCode());
            System.out.println(e.getSQLState());
            System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}
