I have a method that takes a String parameter and runs it as a DB query. I'd like to read through the ResultSet and populate a 2D array where the 1st dimension is the rows and the 2nd is the columns. I know that
ResultSetMetaData.getMetaData() will give me the number of columns (and thus, the 2nd dimension of the array). I can't figure out how to get the 1st dimension though. I've been trying (with no success) to figure out how to realloc my 2D array after every iteration of
resultSet.next() though. I want to do something similar to the code below. By the way,I know there are holes in the code (especially in terms of calling
new on the array). I just wanted to provide some general idea of what I was trying to do. I'd be very grateful for any help.
String[][] resultString = null;
resultSet = stmt.executeQuery(sqlQuery);
ResultSetMetaData rsmd = resultSet.getMetaData();
int totalColumnsReturned = rsmd.getColumnCount();
String[][totalColumnsReturned] resultString = null;
int i = 0;
while (resultSet.next()) {
for (int j=0; j < totalColumnsReturned; j++) {
resultString[i][j] = (String) getObject(i);
}
i++;
}