package myTestApp; import java.sql.*; public class MySample { public static void main (String[] args) throws SQLException, ClassNotFoundException { // set case switch int i = 0 ; if ( args.length == 0) { // value for the default SQL statement to run i = 0 ; }else { i = Integer.valueOf(args[0].trim()); } int largeProj = 80 ; System.out.println(" =======" ); Connection myTestConn=null; myTestConn=getConnection(); //print pureQuery information myPdqVersion() ; switch (i){ case 0: // perform a SELECT against the "employee" table in the sample database. System.out.println("case 0"); Statement stmt0 = myTestConn.createStatement(); ResultSet rs0 = stmt0.executeQuery("SELECT count(EMPNO) " + "FROM EMPLOYEE WHERE WORKDEPT NOT LIKE 'E21' "); while (rs0.next()) { String myEmpCount = rs0.getString(1) ; System.out.println("case 0 - employee count: " + myEmpCount ); } rs0.close(); stmt0.close(); break; case 1: // perform a SELECT against the "employee" table in the sample database. System.out.println("case 1"); PreparedStatement pStmt1 = myTestConn.prepareStatement( "SELECT COUNT(EMPNO) " + "FROM EMPLOYEE WHERE WORKDEPT NOT IN (?,?) "); pStmt1.setString(1, "D11"); pStmt1.setString(2, "D21"); ResultSet rs1 = pStmt1.executeQuery(); while (rs1.next()) { String myCountryCount = rs1.getString(1) ; System.out.println("case 1 - non-systems employees: " + myCountryCount ); } pStmt1.close(); rs1.close(); break; case 2: // perform a SELECT against the "employee activities" table in the sample database. System.out.println("case 2"); PreparedStatement pStmt2 = myTestConn.prepareStatement( "SELECT COUNT(DISTINCT PROJNO) " + "FROM EMPPROJACT WHERE ACTNO >= ? "); pStmt2.setInt(1, largeProj ); ResultSet rs2 = pStmt2.executeQuery(); while (rs2.next()) { String myCountryCount = rs2.getString(1) ; System.out.println("case 2 - large projects: " + myCountryCount ); } pStmt2.close(); rs2.close(); break; } // end switch myTestConn.close(); System.out.println("Finished case " + i); } //end main public static Connection getConnection() throws SQLException, ClassNotFoundException { Connection jdbcCon=null; try { Class.forName("com.ibm.db2.jcc.DB2Driver"); // TODO update connection information jdbcCon=DriverManager.getConnection( "jdbc:db2://localhost:50000/SAMPLE:" + "retrieveMessagesFromServerOnGetMessage=true;", "testuser1", "mypwd"); } catch (SQLException e) { System.out.println(e); } return jdbcCon ; } public static void myPdqVersion() { System.out.println( com.ibm.pdq.tools.DataVersion.getVersion()); // Uncomment to display other pureQuery configuratin information // System.out.println( com.ibm.pdq.tools.DataVersion.getConfiguration()); // System.out.println( com.ibm.pdq.tools.DataVersion.getFeatures()); // System.out.println( com.ibm.pdq.tools.DataVersion.validate()); System.out.println(" =======" ); } }