import java.util.*;
 /**
 * A simple client to demonstrate the use of DatabaseUtility class.
 * @author Z Paracha.
 *<br><b>Copyright</b>: zparacha.com (c) 2007</p> 
 */
public class DatabaseClient{
 public static void main(String args[]) throws Exception{
 //Initialize required parameters. 
 String dbURL = "qcompass:1521:q2bl29G"; //database URL
 String dbUser = "compassprd"; //database User ID
 String dbPw = "q29g_95"; //database Password
 HashMap keyMap = new HashMap(); //HashMap to hold key-value pairs for where clause.
 String tableName ="fraud_values"; //Table name to get the data from.
 
 Vector columnVector = new Vector(); //vector to hold columns name that we are retrieving.
 String col = "operator_id", //column name we are interested.
        col2 = "application_id";
 //if we want to retrieve all columns do following
// String col = "*"; and then add this variable to columnVector. 
//Another way of retrieving all columns is to call getAllData() method.
 
 //Put the column names in columnVector.
 columnVector.addElement(col);
 columnVector.addElement(col2);
 //Populate keyMap. 
 //First argument is the column_name and the second is the value of the column.
 //They both must be String values. Even if the the data type is not String in database put the value in
 //map as a String.
 keyMap.put("element_id","4");
 keyMap.put("element01","63485"); //you can put as many key-value pais in keyMap as you wish.
 //if your keyMap is null or empty all the rows for the table will be retrieved.
 
 //Call the method to retrieve data from the database.
 Vector result =DatabaseUtility.getData(tableName,columnVector,keyMap,dbURL,dbUser ,dbPw);
 //result = DatabaseUtility.getAllData(tableName,keyMap,dbURL,dbUser,dbPw);
 
 //Now iterate through the vector to obtain data.
 //The vector has HashMap objects. Each HashMap object in the vector represents one row of the database.
 //So if 5 rows were returned from the database there will be five HashMap objects in the vector.
 //Each HashMap object will have column_name and value pairs.
 Iterator itr = result.iterator();
 int rowId = 0;
 while(itr.hasNext()){
  System.out.println("Row " + ++rowId+":");
  HashMap m = (HashMap)itr.next();
  //Get the name of columns.
  Set keys = m.keySet(); 
  Iterator keyItr = keys.iterator();
  while(keyItr.hasNext()){
   String colName = (String)keyItr.next();
   String value = (String)m.get(colName);
  System.out.println(colName +" = " + value);
  }
  System.out.println("*************************");
 }
 }

}