Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)
With java.sql.ResultSet is there a way to get a column's name as a String by using the column's index? I had a look through the API doc but I can't find anything.

1 Answer

0 votes
by (46k points)

You can get the aforementioned info from the ResultSet metadata. Descry ResultSetMetaData

e.g.

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

 ResultSetMetaData rsmd = rs.getMetaData();

 String name = rsmd.getColumnName(1);

and you can notice the column name from there. If you do

choose x as y from table

then rsmd.getColumnLabel() will get you the retrieved label name also.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 6, 2020 in SQL by Appu (6.1k points)

Browse Categories

...