Java SQL Table Column getColumnName(boolean isShowRowNum, ResultSet rs)

Here you can find the source of getColumnName(boolean isShowRowNum, ResultSet rs)

Description

get Column Name

License

Open Source License

Declaration

public static Map<Integer, String> getColumnName(boolean isShowRowNum, ResultSet rs) throws Exception 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 hangum./*  w w w  .  j a  v a  2  s .c o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     hangum - initial API and implementation
 ******************************************************************************/

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

import java.util.HashMap;
import java.util.Map;

public class Main {

    public static Map<Integer, String> getColumnName(boolean isShowRowNum, ResultSet rs) throws Exception {
        Map<Integer, String> mapColumnName = new HashMap<Integer, String>();
        int intStartIndex = 0;

        if (isShowRowNum) {
            intStartIndex++;
            mapColumnName.put(0, "#");
        }

        ResultSetMetaData rsm = rs.getMetaData();
        int columnCount = rsm.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            mapColumnName.put(i + intStartIndex, rsm.getColumnLabel(i + 1));
        }

        return mapColumnName;
    }

    public static Map<Integer, String> getColumnName(ResultSet rs) throws Exception {
        return getColumnName(false, rs);
    }
}

Related

  1. getColumn(ResultSet result, int col)
  2. getColumnDisplaySize(int col, ResultSetMetaData rsmd)
  3. getColumnIndexFromColumnName(ResultSetMetaData metaData, String columnName)
  4. getColumnLabelMap(ResultSet resultSet)
  5. getColumnMetaData(Connection conn, String table, String column)
  6. getColumnName(ResultSetMetaData meta, int column)
  7. getColumnNames(final ResultSet resultSet)
  8. getColumnNames(ResultSet resultSet_)
  9. getColumnNames(ResultSet rs)