Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfBoundException is thrown while adding values to ArrayList in Java #110

Open
Gurunathan5029 opened this issue Dec 26, 2016 · 1 comment

Comments

@Gurunathan5029
Copy link

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;

	} catch (Exception exception) {
		exception.printStackTrace();
	} 
	return null;
}

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

@BraisGabin
Copy link
Collaborator

How is this related with TableFixHeaders? Use StackOverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants