It would definitely help if you could provided a call stack for the
NPE. If I understand correctly, it occurs when rs. next is called.
I do not think your code does what you intend it to do. I think that
rs.first() followed by rs.next() will position on the second row of the
result set. Hence, the values of the first row will not be accessed.
Also, the code will not be very efficient for large result sets since
rs.last() will in most cases materialize the entire query in order to
get to the last row.
--
Øystein
Mark Hiles wrote:
Ok, need a little guidance again..
I perform a query which returns some results that I'd like to store in a
2-dimensional array. But when I try running a loop to go through the results, I
get a null pointer exception happening. I know that the query is returning 2
rows of results, so why can't I go through them?
Here's an example of the kind of thing I'm trying to do...
rs = stmt.executeQuery("...");
rs.last();
arr = new String[rs.getRow()][2];
rs.first();
int i;
for(i = 0; rs.next(); ++i) { // null pointer exception
arr[i][0] = rs.getString("...");
arr[i][1] = rs.getInt("...");
}