private void executeQuery(int i, int bid, String type, java.util.Date from, java.util.Date to, String city) {
Connection con;
PreparedStatement query1, query2, query3, query4;
Statement stmt;
ResultSet rs;
try {
// load the jdbc driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
System.out.println("Loaded the JDBC Driver");
// create a db connection
con = DriverManager.getConnection(DBURL);
System.out.println("Created a JDBC connection to the data source.");
// create a statement object
query1 = con.prepareStatement("SELECT cid FROM Customer C, Application A WHERE C.serial# = A.serial# AND C.bid = ? AND A.type='creditLine'");
query2 = con.prepareStatement("SELECT last FROM Customer C WHERE C.submitDate >= ? AND C.submitDate <= ? AND C.serial# IN ( SELECT serial# FROM Application WHERE type='personalLoan' )");
query3 = con.prepareStatement("SELECT serial# FROM Customer C WHERE C.city= ? ");
query4 = con.prepareStatement("SELECT last FROM Customer C WHERE C.serial# IN ( SELECT serial# FROM receives R WHERE R.bid=2345 AND R.date >= '2006-12-01' AND R.date <= '2006-12-31' )");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String myQuery;
// submit the query to DB2
if (i == 0) {
/*
query1.setInt(1, bid);
System.out.println("1");
query1.executeUpdate();
System.out.println("2");
rs = query1.executeQuery();
while (rs.next()) {
int cid = rs.getInt("cid");
System.out.println("cid=" + cid);
}
*/
myQuery = "SELECT cid FROM Customer C, Application A WHERE C.serial# = A.serial# AND C.bid=" + bid + " AND A.type='" + type + "'";
// submit the query to DB2
rs = stmt.executeQuery(myQuery);
while (rs.next()) {
int cid = rs.getInt("cid");
System.out.println("cid=" + cid);
}
} else if (i == 1) {
} else if (i == 2) {
} else if (i == 3) {
}
// close the db connection
con.close();
System.out.println("Disconnected from data source.");
System.out.println("JDBC exit from class Setup.");
} // end try
catch(ClassNotFoundException e) // thrown by Class.forName( ... )
{ System.err.println("Could not load JDBC Driver.");
System.err.println("Exception: " + e);
e.printStackTrace();
}
catch(SQLException e)
{ System.err.println("SQLException information:");
while(e != null)
{ System.err.println("Error msg: " + e.getMessage());
System.err.println("SQLState: " + e.getSQLState());
System.err.println("Error code: " + e.getErrorCode());
e.printStackTrace();
// for drivers supporting chained exceptions ...
e = e.getNextException();
}
}
}