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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can use the the ResultSetMetaData (http://java.sun.com/javase/6/docs/api/java/sql/ResultSetMetaData.html) object for that, like this:
This question is old and so are the correct previous answers. But what I was looking for when I found this topic was something like this solution. Hopefully it helps someone.
You can get this info from the
ResultSet
metadata. See ResultSetMetaDatae.g.
and you can get the column name from there. If you do
then
rsmd.getColumnLabel()
will get you the retrieved label name too.The SQL statements that read data from a database query return the data in a result set. The SELECT statement is the standard way to select rows from a database and view them in a result set. The
**java.sql.ResultSet**
interface represents the result set of a database query.Using
MetaData of a result set to fetch the exact column count
http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSetMetaData.html
and further more to bind it to data model table
very nice tutorial here : http://www.tutorialspoint.com/jdbc/
When you need the column names, but do not want to grab entries:
NOTE: Only works with MySQL
@Cyntech is right.
Incase your table is empty and you still need to get table column names you can get your column as type Vector,see the following: