Here I am trying to get the row values from database and adding it to the ArrayList. The values are getting added without any error but the exception is thrown at the end of the loop.
java.lang.IndexOutOfBoundsException: Index: 338, Size: 338
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at net.thucydides.showcase.cucumber.webdriverclasses.SQLSupportClass.retrievelist(SQLSupportClass.java:42)
Working around this for quite some time but never got the solution. Help me out with suggestions and answers
Here I am trying to get the row values from database and adding it to the ArrayList. The values are getting added without any error but the exception is thrown at the end of the loop.
Code: public ArrayList retrievelist(String database, String field, String table) {
Statement statement;
try {
statement = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); String exten = ".dbo."; String query = "select " + "" + field + "" + " from " + "[" + database + "]" + "" + exten + "" + "[" + table
"]"; ResultSet rs = statement.executeQuery(query); ArrayList records = new ArrayList();
System.out.println("HIHIHI" + query);
while(rs.next()) { System.out.println(rs.getString(field) + records.size());
records.add(rs.getString(field)); System.out.println(records.get(records.size()-1));
} return records;
}
Output: lotto
Jasonhhhhhhhhhhhhhhhhhhhhhhhhh336 Jasonhhhhhhhhhhhhhhhhhhhhhhhhh Pamela 337 Pamela
[main] INFO net.serenitybdd.core.Serenity - STEP ERROR: java.lang.IndexOutOfBoundsException: Index: 338, Size: 338 [main] INFO net.serenitybdd.core.Serenity - STEP ERROR: java.lang.IndexOutOfBoundsException: Index: 338, Size: 338 [main] INFO net.serenitybdd.core.Serenity - FINISHING STEP [main] ERROR net.serenitybdd.core.Serenity -
/ / | _| __/ __| | | / \ | | | | _| \ ()____| | | | | | \ \ | | | | / \ | || | | | | | | | |__| | | | | | ) || | | / __ \ | || || || || | () | | || ||/ || ||// __|||___/ \\
TEST FAILED WITH ERROR: DB check
[main] ERROR net.serenitybdd.core.Serenity - TEST FAILED AT STEP DB retrievelist: FIRSTNAME, Guru, EMPLOYEE [main] ERROR net.serenitybdd.core.Serenity - Index: 338, Size: 338
[31mFailed scenarios:[0m [31mdebug.feature:46 [0m# Scenario Outline: DBCheck
4 Scenarios ([31m1 failed[0m, [32m3 passed[0m) 26 Steps ([31m1 failed[0m, [32m25 passed[0m) 2m10.323s
java.lang.IndexOutOfBoundsException: Index: 338, Size: 338 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at net.thucydides.showcase.cucumber.webdriverclasses.SQLSupportClass.retrievelist(SQLSupportClass.java:42)
Working around this for quite some time but never got the solution. Help me out with suggestions and answers