views:

103

answers:

1

Below is my code trying to retrieve table name form Resultset

ResultSet rs = stmt.executeQuery("select * from product");

ResultSetMetaData meta = rs.getMetaData();
int count = meta.getColumnCount();
for (int i=0; i<count; i++) {
  System.out.println(meta.getTableName(i));
}

But it returns empty, no mention it is a join select resultset. Is there any other approaches to retrieve table name from reusltset metadata?

A: 

The column indices passed to getTableName() start at 1. Change your loop to read:

for (int i=1; i<=count; i++) {
  System.out.println(meta.getTableName(i));
}
Sugerman