D:\JavaFrameworks\InsuranceFramework\src\java\db_adapter\UPPER_COUNT.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 //import org.apache.log4j.Logger;
26 //import org.apache.log4j.PropertyConfigurator;
27 
28 import utils.*;
29 import constants.*;
30 
31 public class UPPER_COUNT
32 {
33     Connection  localConnection = null;
34 
35     public UPPER_COUNT()
36     {
37         BD_Connector localBD_Connector = new BD_Connector();
38         localConnection = localBD_Connector.getConnection();
39     }
40     /*
41      *
42      */
43      public int select(String passedTableName_1, String subString)
44      {
45         //The following example returns all names, selecting those where the uppercase form of the name starts with “JO”:
46         //  SELECT Name
47         //      FROM Sample.Person
48         //      WHERE UPPER(Name) %STARTSWITH UPPER('Sa')
49         if(null == localConnection)
50             return(Constants.ERROR_RUN);
51         PreparedStatement   localPreparedStatement      = null;
52         ResultSet           localResultSet              = null;
53         //==========================
54         try
55         {
56 
57                 String qryString        = "";
58                 String tableName_1     = DatabaseKeysPropertyManager.getParameter(passedTableName_1);
59                 qryString       =       "SELECT Name FROM "
60                                 + tableName_1
61                                 + ".Person "
62                                 + "WHERE UPPER(Name) %STARTSWITH UPPER('"
63                                 + subString
64                                 + "')";
65 
66                 localPreparedStatement = localConnection.prepareStatement(qryString);
67                 localResultSet = localPreparedStatement.executeQuery();
68                 ArrayList localXYZArrayList = new ArrayList();
69                 //===========================================
70                 while(localResultSet.next())
71                 {
72                         String name = localResultSet.getString("Name");
73                         // work with the names                    
74                 }
75                 localPreparedStatement.close();
76         }
77         catch(MissingResourceException eMissingResourceException)
78         {
79             eMissingResourceException.printStackTrace();
80             return(Constants.ERROR_RUN);
81         }
82         catch(SQLException eSQLException)
83         {
84             eSQLException.printStackTrace();
85             return(Constants.ERROR_RUN);
86         }
87         return(Constants.NORMAL_RUN);
88      }
89 
90 }
91 
92