Java SQL ResultSet Read getAllColumnNamesFromResultSet(ResultSet set)

Here you can find the source of getAllColumnNamesFromResultSet(ResultSet set)

Description

Returns the names of the columns in a ResultSet in the order that they appear in the result.

License

Open Source License

Parameter

Parameter Description
set the ResultSet to get the columns from.

Exception

Parameter Description
SQLException if something goes wrong.

Return

an array of all of the columns.

Declaration

public static String[] getAllColumnNamesFromResultSet(ResultSet set) throws SQLException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013-2014 Black Rook Software
 * 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/lgpl-2.1.html
 ******************************************************************************/

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

public class Main {
    /**//from   www . j a v  a 2  s .  c  o m
     * Returns the names of the columns in a ResultSet in the order that they appear in the result.
     * @param set the ResultSet to get the columns from.
     * @return an array of all of the columns.
     * @throws SQLException if something goes wrong.
     */
    public static String[] getAllColumnNamesFromResultSet(ResultSet set) throws SQLException {
        ResultSetMetaData md = set.getMetaData();
        String[] out = new String[md.getColumnCount()];
        for (int i = 0; i < out.length; i++)
            out[i] = md.getColumnName(i + 1);
        return out;
    }
}

Related

  1. get(ResultSet rs, String name)
  2. getAllColumnNames(ResultSet rs)
  3. getAllData(ResultSet rs)
  4. getAllRow(ResultSet rs)
  5. getAllValueMaps(ResultSet input)
  6. getArray(ResultSet resultSet, String columnLabel, Class clazz)