D:\JavaFrameworks\InsuranceFramework\src\java\db_adapter\Distinct.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 
 23 //import org.apache.log4j.Logger;
 24 //import org.apache.log4j.PropertyConfigurator;
 25 
 26 import utils.*;
 27 import constants.*;
 28 
 29 public class Distinct 
 30 {
 31     Connection  localConnection = null;
 32 
 33     public Distinct()
 34     {
 35         BD_Connector localBD_Connector = new BD_Connector();
 36         localConnection = localBD_Connector.getConnection();
 37     }
 38     // The SQL DISTINCT clause allows you to remove duplicates from the result set.
 39     // The SQL DISTINCT clause can only be used with SQL SELECT statements.
 40     /*
 41      *
 42      */
 43      public int selectUsingDISTINCT(String passedTableName, String passedTableName_2, String city, String state)
 44      {
 45         if(null == localConnection)
 46             return(Constants.ERROR_RUN);
 47         PreparedStatement   localPreparedStatement      = null;
 48         ResultSet           localResultSet              = null;
 49         //==========================
 50         try
 51         {
 52             // SELECT DISTINCT city, state
 53             // FROM passedTableName_1;
 54 
 55                 String qryString        = "";
 56                 String tableName_1        = DatabaseKeysPropertyManager.getParameter(passedTableName);
 57                 //==========================
 58                 qryString       =       "SELECT DISTINCT "
 59                                 + city
 60                                 + ", "
 61                                 + state
 62                                 + " FROM "
 63                                 + passedTableName;
 64 
 65                 localPreparedStatement = localConnection.prepareStatement(qryString);
 66                 localResultSet = localPreparedStatement.executeQuery();
 67                 ArrayList localXYZArrayList = new ArrayList();
 68                 //===========================================
 69                 while(localResultSet.next())
 70                 {
 71                     // Start retrieving your fields
 72                     String xStringValue = localResultSet.getString("Location_Number");
 73                     long   xLongValue   = localResultSet.getLong("long lll");
 74                     int    xIntValue    = localResultSet.getInt("int iii");
 75                     int    xIntValue2   = localResultSet.getInt(4);
 76                 }
 77                 localPreparedStatement.close();
 78         }
 79         catch(MissingResourceException eMissingResourceException)
 80         {
 81             eMissingResourceException.printStackTrace();
 82             return(Constants.ERROR_RUN);
 83         }
 84         catch(SQLException eSQLException)
 85         {
 86             eSQLException.printStackTrace();
 87             return(Constants.ERROR_RUN);
 88         }
 89         return(Constants.NORMAL_RUN);
 90      }
 91     /*
 92      *
 93      */
 94      public int selectUsingDISTINCT(String passedTableName)
 95      {
 96         if(null == localConnection)
 97             return(Constants.ERROR_RUN);
 98         PreparedStatement   localPreparedStatement      = null;
 99         ResultSet           localResultSet              = null;
100         //==========================
101         try
102         {
103             // select NAME, ITEM_DESCRIPTION, DISTRIBUTED_DATE, DISTRIBUTED_TIME FROM table_1
104             // where NAME in (select distinct NAME FROM table_1)
105                 String qryString        = "";
106                 String tableName_1        = DatabaseKeysPropertyManager.getParameter(passedTableName);
107                 //==========================
108                 qryString       =       "SELECT "
109                                 + " NAME, ITEM_DESCRIPTION, DISTRIBUTED_DATE, DISTRIBUTED_TIME "
110                                 + " FROM "
111                                 + passedTableName
112                                 + " WHERE "
113                                 + "NAME "
114                                 + " IN "
115                                 + "in (select distinct NAME FROM "
116                                 + passedTableName
117                                 + ")";
118 
119                 localPreparedStatement = localConnection.prepareStatement(qryString);
120                 localResultSet = localPreparedStatement.executeQuery();
121                 ArrayList localXYZArrayList = new ArrayList();
122                 //===========================================
123                 while(localResultSet.next())
124                 {
125                     String xStringValue = localResultSet.getString("Location_Number");
126                     long   xLongValue   = localResultSet.getLong("long lll");
127                     int    xIntValue    = localResultSet.getInt("int iii");
128                     int    xIntValue2   = localResultSet.getInt(4);
129                 }
130                 localPreparedStatement.close();
131         }
132         catch(MissingResourceException eMissingResourceException)
133         {
134             eMissingResourceException.printStackTrace();
135             return(Constants.ERROR_RUN);
136         }
137         catch(SQLException eSQLException)
138         {
139             eSQLException.printStackTrace();
140             return(Constants.ERROR_RUN);
141         }
142         return(Constants.NORMAL_RUN);
143      }
144 }
145 
146