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

0

2 Answers 2

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()

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.