gudii9
asked on
reading a text document
I have following text data in a pipe | delimitted text file
999|5555|6666|PPP|9/9/200915:49|1444-AAA_111|FINISH
998|5554|6666|PPP|9/9/200915:49|1444-AAA_111|FINISH
997|5553|6666|PPP|9/9/200915:49|1444-AAA_111|FINISH
996|5552|6666|PPP|9/9/200915:49|1444-AAA_111|FINISH
I am reading above data into String array called rows.
Then 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);
//above line printing 4 correctly as there are four lines in the text file
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,S tring>>();
// i need to manipulate array of 4*6 I believe here to read the values specifically first and second value to pass to below query(as username and password) to check againest database which I am not sure how to do it. ???
try{
Class.forName("com.mysql.jdbc.Driver ").newInst ance();
Connection con = DriverManager.getConnection("jdbc:my sql://loca lhost:3306 /test","ro ot", "root");
Statement stmt = con.createStatement();
String usernameColumn = genericImporterProp.getString("usern ameColumn" );
String passwordColumn = genericImporterProp.getString("passw ordColumn" );
ResultSet rs1 = stmt.executeQuery("select * from login where " + usernameColumn + "='"+username+"' and " + passwordColumn + "='"+Double.parseDouble(stringCellVa lue)+"'");
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-- >"+myUseri dToPass);
System.out.println("myPasswordToPass -->"+myPas swordToPas s);
}
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" );
}
Preferably without using java 1.5 generics is much good as server is running on java 1.4.
Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
ASKER
i cannot use scanner as server running on java 1.4 not java 1.5. please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window