private static void commandParamsSample(Connection conn, int idProdDep, int idDevDep)
{
// create a command
DBCommand cmd = db.createCommand();
// Create cmd parameters
DBCommandParam curDepParam = cmd.addParam(); // Current Department
DBCommandParam genderParam = cmd.addParam(); // Gender ('M' or 'F')
// Define the query
cmd.select(T_EMP.C_FULLNAME);
cmd.join (T_EMP.C_EMPLOYEE_ID, db.V_EMPLOYEE_INFO.C_EMPLOYEE_ID);
cmd.where (T_EMP.C_GENDER.is(genderParam));
cmd.where (db.V_EMPLOYEE_INFO.C_CURRENT_DEP_ID.is(curDepParam));
System.out.println("Perfoming two queries using a the same command with different parameter values.");
DBReader r = new DBReader();
try {
// Query all females currently working in the Production department
System.out.println("1. Query all females currently working in the production department");
// Set command parameter values
genderParam.setValue('F'); // set gender to female
curDepParam.setValue(idProdDep); // set department id to production department
// Open reader using a prepared statement (due to command parameters!)
r.open(cmd, conn);
// print all results
System.out.println("Females working in the production department are:");
while (r.moveNext())
System.out.println(" " + r.getString(T_EMP.C_FULLNAME));
r.close();
// Second query
// Now query all males currently working in the development department
System.out.println("2. Query all males currently working in the development department");
// Set command parameter values
genderParam.setValue('M'); // set gender to female
curDepParam.setValue(idDevDep); // set department id to production department
// Open reader using a prepared statement (due to command parameters!)
r.open(cmd, conn);
// print all results
System.out.println("Males currently working in the development department are:");