Java SQL Table Column getColumnsNames(ResultSet rs)

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

Description

get Columns Names

License

Open Source License

Declaration

public static String[] getColumnsNames(ResultSet rs) 

Method Source Code


//package com.java2s;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String[] getColumnsNames(ResultSet rs) {
        String[] columnNames = null;
        try {/*from  ww  w . j  a v a  2 s . c  o  m*/
            ResultSetMetaData rsmd = rs.getMetaData();
            List<String> lstColumnNames = new ArrayList<String>();
            for (int i = 0; i < rsmd.getColumnCount(); i++) {
                lstColumnNames.add(rsmd.getColumnName(i));
            }
            columnNames = new String[lstColumnNames.size()];

            columnNames = lstColumnNames.toArray(columnNames);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return columnNames;
    }
}

Related

  1. getColumnNames(ResultSet rs)
  2. getColumnNames(ResultSet rs)
  3. getColumnNamesFromResultSet(ResultSet rs)
  4. getColumns(ResultSetMetaData rsmd)
  5. getColumns(ResultSetMetaData rsMetaData)
  6. getColumnType(ResultSet resultSet, int i, Map typeCache)
  7. getColumnType(ResultSetMetaData rsm)
  8. getColumnType(ResultSetMetaData rsmd, int idx)
  9. getColumnTypes(ResultSet rs)