reading a text document

I have following text data in a pipe | delimitted text file

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
I am reading above data into String array called rows.

Then i am calling following method like below from main method

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,String>>();

// 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. ???

                        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 ({
                                    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>();

                              for(HashMap<String,String> newMapDetail : missingList) {
                                    String myUseridToPass = newMapDetail.get("username");
                                    String myPasswordToPass = newMapDetail.get("password");



                  catch(Exception e){


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

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


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
Who is Participating?
    public static void main(String[] args) throws Exception {
        BufferedReader in = null;

        try {
            in = new BufferedReader(new FileReader(new File("data.txt")));

            String line = null;

            while ((line = in.readLine()) != null) {
                String[] creds = line.split("\\|", 3);
        } finally {
            if (in != null) {
                try {
                } catch (IOException e) { /* ignore */

Open in new window

I'd probably handle the file something like:


import java.util.*;

public class ReadIt {
    public static void main(String[] args) throws Exception {
        Scanner s = new Scanner(new File("data.txt"));

        while (s.hasNextLine()) {
            String[] creds = s.nextLine().split("\\|", 3);


    static void process(String[] row) {
        System.out.printf("username=%s,password=%s\n", row[0], row[1]);

Open in new window

gudii9Author Commented:
i cannot use scanner as server running on java 1.4 not java 1.5. please advise
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.