D:\JavaFrameworks\InsuranceFramework\src\java\db_adapter\AS_Aliases.java
  1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 
  6 package db_adapter;
  7 
  8 /**
  9  *
 10  * @author sameldin
 11  */
 12 import java.io.*;
 13 import java.sql.Connection;
 14 import java.sql.DriverManager;
 15 import java.sql.PreparedStatement;
 16 import java.sql.ResultSet;
 17 import java.sql.SQLException;
 18 import java.util.ArrayList;
 19 import java.util.Hashtable;
 20 import java.util.MissingResourceException;
 21 import java.util.ResourceBundle;
 22 import java.util.Calendar;
 23 import java.util.Date;
 24 import java.text.SimpleDateFormat;
 25 
 26 
 27 //import org.apache.log4j.Logger;
 28 //import org.apache.log4j.PropertyConfigurator;
 29 
 30 import utils.*;
 31 import constants.*;
 32 
 33 
 34 public class AS_Aliases
 35 {
 36     Connection  localConnection = null;
 37 
 38     public AS_Aliases()
 39     {
 40         BD_Connector localBD_Connector = new BD_Connector();
 41         localConnection = localBD_Connector.getConnection();
 42     }
 43      /*
 44       *
 45       */
 46      public int selectUsingAs(String customerTable, String OrderTable, String PurchaseTable, long productID)
 47      {
 48         //  Aliases are used for:
 49         //      to shorten SQL syntax
 50         //      to enable multiple uses of the same table within a single SELECT Statement
 51         //  ========================================================
 52         //  SELECT customerName,customerContact
 53         //  FROM   CustomerTable AS CT, OrderTable AS OT, PurchaseTable AS PT
 54         //  WHERE CT.customerName = OT.customerName
 55         //  AND PT.customerContact = OT.customerContact
 56         //  AND PT.productID = '0123';
 57          if(null == localConnection)
 58             return(Constants.ERROR_RUN);
 59          PreparedStatement  localPreparedStatement  = null;
 60          ResultSet          localResultSet          = null;
 61          //===================================
 62          try
 63          {
 64             String qryString    = "";
 65             String localCustomerTable       = DatabaseKeysPropertyManager.getParameter(customerTable);
 66             String localOrderTable          = DatabaseKeysPropertyManager.getParameter(OrderTable);
 67             String localPurchaseTable       = DatabaseKeysPropertyManager.getParameter(PurchaseTable);
 68             //=============================
 69             qryString   =       "SELECT customerName, customerContact"
 70                             + " FROM  "
 71                             + localCustomerTable
 72                             + " AS CT, "
 73                             + localOrderTable
 74                             + " AS OT,"
 75                             + localPurchaseTable
 76                             + " AS PT "
 77                             + "AND PT.customerContact = OT.customerContact "
 78                             + "AND "
 79                             + "PT.productID"
 80                             + "="
 81                             + productID;
 82                 //===============================
 83                 localPreparedStatement = localConnection.prepareStatement(qryString);
 84                 localResultSet = localPreparedStatement.executeQuery();
 85                 ArrayList localXYZArrayList = new ArrayList();
 86                 //===========================================
 87                 while(localResultSet.next())
 88                 {
 89                     // Start retrieving your fields
 90                     String xStringValue = localResultSet.getString("Location_Number");
 91                     long   xLongValue   = localResultSet.getLong("long lll");
 92                     int    xIntValue    = localResultSet.getInt("int iii");
 93                     int    xIntValue2   = localResultSet.getInt(4);
 94                 }
 95 
 96             localPreparedStatement = localConnection.prepareStatement(qryString);
 97             localResultSet = localPreparedStatement.executeQuery();
 98 
 99          }
100          catch(MissingResourceException eMissingResourceException)
101          {
102             eMissingResourceException.printStackTrace();
103             return(Constants.ERROR_RUN);
104          }
105          catch(SQLException eSQLException)
106          {
107             eSQLException.printStackTrace();
108             return(Constants.ERROR_RUN);
109          }
110         return(Constants.NORMAL_RUN);
111      }
112 
113 }
114 
115