// 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.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SomeDB2Stuff {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.ibm.db2.jcc.DB2Driver");
        Connection con = DriverManager.getConnection("jdbc:db2://localhost:50000/Test", "xxxx", "xxxx");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT f2,COUNT(*) AS n FROM t1 WHERE f1 > 1 GROUP BY f2");
        while(rs.next()) {
            String f2 = rs.getString(1);
            int n = rs.getInt(2);
            System.out.println(f2 + " " + n);
        }
        rs.close();
        stmt.close();
        con.close();
    }
}
