Hi, I am working on a couple of Java classes to be used with Selenium RC.
We've got some old Access databases and tables full information to be used in tests cases so I thought it would be a good idea to have a class with methods to make pulling information from Access easier and quicker.
All was going well until I made a method to provide an ArrayList containing String[] arrays (the String[]'s contain the fields in the row) to the TestNG DataProvider method.
System.out.println(result[3]);
Will output the third element, in this case 'firstName', correctly e.g.
GARY
JERRY
JO
However it seems all the String[] in my ArrayList contain the same array - the last one added.
If I access one using:
The same name is always displayed e.g JO, JO, JO.
Any ideas what I'm doing wrong?
We've got some old Access databases and tables full information to be used in tests cases so I thought it would be a good idea to have a class with methods to make pulling information from Access easier and quicker.
All was going well until I made a method to provide an ArrayList containing String[] arrays (the String[]'s contain the fields in the row) to the TestNG DataProvider method.
Code:
[SIZE=2]String[] result = new String[rs.getMetaData().getColumnCount() + 1];[/SIZE]
[SIZE=2]ArrayList<String[]> results = new ArrayList<String[]>();[/SIZE]
[SIZE=2]while (rs.next()) {[/SIZE]
[SIZE=2]for (int colCounter = 1; colCounter <= columnCount; colCounter++) {[/SIZE]
[SIZE=2]if (rs.getString(colCounter) == null) {[/SIZE]
[SIZE=2]result[colCounter] = "";[/SIZE]
[SIZE=2]} else {[/SIZE]
[SIZE=2]result[colCounter] = rs.getString(colCounter);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]results.add(rowCounter, result); [/SIZE]
[SIZE=2]rowCounter++;[/SIZE]
[SIZE=2][B]System.out.println(result[3]);[/B][/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]System.out.println("getRows Query: " + results.size() + " Results Returned.");[/SIZE]
System.out.println(result[3]);
Will output the third element, in this case 'firstName', correctly e.g.
GARY
JERRY
JO
However it seems all the String[] in my ArrayList contain the same array - the last one added.
If I access one using:
Code:
[SIZE=2]String[] rowToCheck = null;[/SIZE]
[SIZE=2]for (int i = 0; i < results.size(); i++){[/SIZE]
[SIZE=2]rowToCheck = results.get(i);[/SIZE]
[SIZE=2]System.out.println(rowToCheck[3]);[/SIZE]
[SIZE=2]}[/SIZE]
The same name is always displayed e.g JO, JO, JO.
Any ideas what I'm doing wrong?