using just arraylist by removing hashmap

i am calling following method like below from main method
      checkDatabases(rows);

The implementation code of checkDatabases(rows) is as below



private static void checkDatabases(String[] rows) {
System.out.println("rows.length : "+rows.length);

                  String username="";//this is first cell value of each line of the text
                    String password="";//this is second cell value of each line of the text
            PreparedStatement pstmt = null;      
            List<HashMap<String,String>> missingList = new ArrayList<HashMap<String,String>>();








try{
                        Class.forName("com.mysql.jdbc.Driver").newInstance();
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
                        Statement stmt = con.createStatement();


                        String usernameColumn = genericImporterProp.getString("usernameColumn");
                        String passwordColumn = genericImporterProp.getString("passwordColumn");
                        ResultSet rs1 = stmt.executeQuery("select * from login where "  + usernameColumn + "='"+username+"' and " + passwordColumn + "='"+Double.parseDouble(stringCellValue)+"'");


                        boolean isExist = false;
                        if (rs1!=null) {

                              while (rs1.next()){
                                    isExist=true;
                                    String rec1 = rs1.getString(1);
                                    String rec2 = rs1.getString(2);
                                    System.out.println("rec1 is--"+rec1+"---rec2 is---"+rec2);
                              }
                        }

                        if (!isExist) {
                              HashMap<String,String> mapDetail =new HashMap<String,String>();
                              mapDetail.put("username",username);
                              mapDetail.put("password",password);




                              for(HashMap<String,String> newMapDetail : missingList) {
                                    String myUseridToPass = newMapDetail.get("username");
                                    String myPasswordToPass = newMapDetail.get("password");
                                    System.out.println("myUseridToPass-->"+myUseridToPass);
                                    System.out.println("myPasswordToPass-->"+myPasswordToPass);
                                   
                              }


                              missingList.add(mapDetail);

                        }


                        //pstmt.close();
                        con.close();
                  }
                  catch(Exception e){

                        System.out.println("e-->"+e);
                  }
            }

            System.out.println("Missing List : "+missingList);

            generateCsvFile("c://MissingList.csv", missingList);
            sendErrorEmail("c://MissingList.csv");

      }


 
I would like to enhance my program by just using ArrayList for usernames and passwords to query on databse by getting rid of HashMaps.

I need to cast the objects within the list when I refer to them.



I need to  Create a class to hold your username and password strings, and then objects of that class can live in my missingList (the ArrayList).

How can I achieve it.I cannot use java 1.5 either. Only java 1.4 I have to use.

Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
LVL 7
gudii9Asked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
Please paste the output of the following:
private static void checkDatabases(String[] rows) {
   System.out.println("rows.length : "+rows.length);
   System.out.println(Arrays.toString(rows)); 
}

Open in new window

0
 
gudii9Author Commented:
After getting 'rows' which has contents of entire text file there one other level down processing i have to do on 'stra'  to get actual line level data delimitted by pipe
      public static void main( String [] args ) {
static ResourceBundle genProp = ResourceBundle.getBundle("docImpExt");
String fileTypeNameColumn = genProp.getString("fileTypeName");

if (fileTypeNameColumn.endsWith(".xls")){
                  System.out.println("Excel file");
                  Vector dataHolder=read(fileName);
                  checkDatabase(dataHolder);
            }
            else{
                  try {
                        String strContent = Storage.retrieveData("C:\\Test.txt");
                        String [] rows = strContent.split(genProp.getString("row.seperator"));                        
                        checkDatabases(rows);
                  } catch (Exception ex) {

                        ex.printStackTrace();
                  }
            }
      }


}

private static List checkDatabases(String[] rows) {
      if(rows!=null){
                  for (int idx = 0 ; idx < rows.length; idx++)
                  {
                        String [] stra = rows[idx].split(genProp.getString("index.data.separator"));
                                System.out.println("stra.length--->"+stra.length);
//here i have to get some how first two cell vaues of each line of the text attached file by calling some index method which i am not sure then pass to ArrayList without HashMap and query the database using first two values
like
999 5555
998 5554
997 5553
996 5552




999|5555|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
998|5554|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
997|5553|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
996|5552|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH




>>>System.out.println("rows.length : "+rows.length); is 4
>>        System.out.println("stra.length--->"+stra.length); is 7
System.out.println("Arrays.toString(rows)----->"+Arrays.toString(rows));
is
Arrays.toString(rows)----->

999|5555|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
998|5554|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
997|5553|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
996|5552|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
0
 
CEHJCommented:
That's not the output from the code i asked for
0
 
gudii9Author Commented:
I am Here is the exact output and the text file
System.out.println("rows.length : "+rows.length);
4
System.out.println(Arrays.toString(rows));
999|5555|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
998|5554|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
997|5553|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
996|5552|6666|PPP|9/9/2009 15:49|1444-AAA_111|FINISH
Test.txt
0
 
CEHJCommented:
System.out.println(Arrays.toString(rows)); 

Open in new window

It's impossible to call Arrays.toString without causing the output to be preceded by '[' and ended by ']' so i don't see how that can be the output
0
All Courses

From novice to tech pro — start learning today.