topbeagle
topbeagle

Reputation: 11

Java Result Set

I am using Eclipse SDK 3.2.0, and I am connecting to Oracle 11g using Java. I am using a simple JDBC connection. I am assigning my queried data to the Result set function. I am able to get one column at a time using rs.getstring. How can I get all the columns printed one a time within my 'while' loop using rs.next()?

Upvotes: 0

Views: 109

Answers (2)

Julien May
Julien May

Reputation: 2051

What about:

while(rs.next()) {
  for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
    System.out.println("col-nr: %d - %s", i, rs.getString(i));
  }
}

Upvotes: 3

Cheung
Cheung

Reputation: 174

I guess you want get all columns data. you can try ResultSetMetaData class.

ResultSet rs = xxx;
ResultSetMetaData rsmd =rs.getMetadata();

Upvotes: 0

Related Questions