Java SQL Table Column hasColumn(String columnName, ResultSet resultSet)

Here you can find the source of hasColumn(String columnName, ResultSet resultSet)

Description

has Column

License

Mozilla Public License

Declaration

public static boolean hasColumn(String columnName, ResultSet resultSet) 

Method Source Code


//package com.java2s;
/*//from ww w.  j a  v  a2 s  . c  om
 * Copyright (c) 2012, Mayocat <hello@mayocat.org>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

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

public class Main {
    public static boolean hasColumn(String columnName, ResultSet resultSet) {
        ResultSetMetaData meta = null;
        try {
            meta = resultSet.getMetaData();
            int columnCount = meta.getColumnCount();

            for (int i = 1; i < columnCount + 1; i++) {
                if (meta.getColumnName(i).equals(columnName)) {
                    return true;
                }
            }
        } catch (SQLException e) {
            // Ignore
        }
        return false;
    }
}

Related

  1. getIndexName(Connection conn, String table, String column)
  2. getRange(Connection C, String table, String column)
  3. hasColumn(final ResultSet row, final String columnName)
  4. hasColumn(ResultSet rs, String columnName)
  5. hasColumn(ResultSet rs, String columnName)
  6. hasColumn(String field, ResultSet rs)
  7. hasColumns(Connection conn, String tableName, Collection colNames)
  8. hasTableAndColumns(Connection conn, String tableName, String... colNames)
  9. indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)