Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading ResultSet Into a 2D Array

843854May 8 2004 — edited May 8 2004
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++;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2004
Added on May 8 2004
1 comment
845 views