0

Possible Duplicate:
Retrieve column names from java.sql.ResultSet

I have query which returns the result set, i want to get the column names which are returned.

i really don't know how to get the column names from result set, it would be great help if some of you could provide me with the sample or example.

how to do this in java.

regards

Community
  • 1
  • 1
Java Questions
  • 7,813
  • 41
  • 118
  • 176

2 Answers2

8

You need the ResultSetMetaData

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
ResultSetMetaData rsmd = rs.getMetaData();

and for your use case, check out getColumnName()

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
3

You can use the ResultSetMetaData class to extract this kind of information.

Example: http://www.java2s.com/Code/Java/Database-SQL-JDBC/SQLstatementResultSetandResultSetMetaData.htm

Endy
  • 698
  • 3
  • 11