Java SQL ResultSet Read getFieldNames(ResultSet rs)

Here you can find the source of getFieldNames(ResultSet rs)

Description

Return field names

License

Open Source License

Parameter

Parameter Description
rs ResultSet to be examinated

Exception

Parameter Description
SQLException an exception

Return

array containing field names

Declaration

private static String[] getFieldNames(ResultSet rs) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class Main {
    /**//w  ww.j a  va2s  .  c  om
     * Return field names
     * @param rs ResultSet to be examinated
     * @return array containing field names
     * @throws SQLException
     */
    private static String[] getFieldNames(ResultSet rs) throws SQLException {
        if (rs == null)
            return null;

        // Return db information based on result set
        ResultSetMetaData metaData = rs.getMetaData();

        // Return filed number of table specified in SQL query
        int col_num = metaData.getColumnCount();
        String[] col_names = new String[col_num];

        // Creates array with field names
        for (int i = 0; i < col_num; i++)
            col_names[i] = metaData.getColumnName(i + 1);

        return col_names;
    }
}

Related

  1. getEnum(ResultSet r, String columnName, Class enumType)
  2. getEnum(ResultSet rs, int index, Class type)
  3. getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues)
  4. getExpectedType(ResultSet resultSet, int columnIndex)
  5. getExplainPlan(ResultSet rs)
  6. getFieldsPresentInResultSet(ResultSet rs)
  7. getFirstGeometryFieldIndex(ResultSet resultSet)
  8. getFirstInt(ResultSet resultSet)
  9. getFlags(ResultSet rs)