H
homerjk
Hello there,
Please God can someone help me before I break my PC.
I have a class that runs a query against an Oracle 10g database. The
query is returning the results I want.
I get two users which is what I want. I have an array created that has
a length of two.
I feed the results of the query into the array...
<code>
int[] engineers = new int[2];
String sql = "select USERID from g_user where role='Engineer'";
PreparedStatement pstmt = tempConn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
engineers = rs.getInt("USERID"); // find result of count
i++;
}
</code>
The very next thing if i try
<code>
System.out.println("engineer array length is " + engineers.length);
System.out.println("engineer array 0 is " + engineers[0]);
System.out.println("engineer array 1 is " + engineers[1]);
</code>
I get....
<code>
engineer array length is 2
java.lang.ArrayIndexOutOfBoundsException: 0
engineer array 0 length is 85
engineer array 1 length is 123
</code>
If i take out the first print message to find the length i get the
same error when i try to access the first element. If i take out the
message to access the length and the first element i get no error
whatsoever! but obviously i cannot do anything useful with my program
because i cannot access the first element.
I thought i was losing my mind, so i created a tiny program with just
this code on its own and it runs perfectly which is making me even
crazier!
What in the name of all that is good could be causing this?! I mean it
is printing out the correct contents and length of the array even
after it shows an error to say outofbounds!
Any help at all is very much appreciated...
Thank you,
J.
Please God can someone help me before I break my PC.
I have a class that runs a query against an Oracle 10g database. The
query is returning the results I want.
I get two users which is what I want. I have an array created that has
a length of two.
I feed the results of the query into the array...
<code>
int[] engineers = new int[2];
String sql = "select USERID from g_user where role='Engineer'";
PreparedStatement pstmt = tempConn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
engineers = rs.getInt("USERID"); // find result of count
i++;
}
</code>
The very next thing if i try
<code>
System.out.println("engineer array length is " + engineers.length);
System.out.println("engineer array 0 is " + engineers[0]);
System.out.println("engineer array 1 is " + engineers[1]);
</code>
I get....
<code>
engineer array length is 2
java.lang.ArrayIndexOutOfBoundsException: 0
engineer array 0 length is 85
engineer array 1 length is 123
</code>
If i take out the first print message to find the length i get the
same error when i try to access the first element. If i take out the
message to access the length and the first element i get no error
whatsoever! but obviously i cannot do anything useful with my program
because i cannot access the first element.
I thought i was losing my mind, so i created a tiny program with just
this code on its own and it runs perfectly which is making me even
crazier!
What in the name of all that is good could be causing this?! I mean it
is printing out the correct contents and length of the array even
after it shows an error to say outofbounds!
Any help at all is very much appreciated...
Thank you,
J.