Java SQL Table Column hasColumn(final ResultSet row, final String columnName)

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

Description

Test if a column name exists within the given result set.

License

Educational Community License

Parameter

Parameter Description
row A result set
columnName A column name

Exception

Parameter Description
SQLException If there is a problem accessing the result set

Return

True if the column name exists in the given result set

Declaration

public static boolean hasColumn(final ResultSet row, final String columnName) throws SQLException 

Method Source Code


//package com.java2s;
//License from project: Educational Community License 

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

public class Main {
    /**/* ww  w.  j av a 2 s .  c  o m*/
     * Test if a column name exists within the given result set.
     *
     * @param row           A result set
     * @param columnName    A column name
     * @return True if the column name exists in the given result set
     * @throws SQLException If there is a problem accessing the result set
     */
    public static boolean hasColumn(final ResultSet row, final String columnName) throws SQLException {
        final ResultSetMetaData metaData = row.getMetaData();
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            final String name = metaData.getColumnName(i);
            if (columnName.equals(name))
                return true;
        }
        return false;
    }
}

Related

  1. getColumnValueFromResultSet(int columnIndex, int argType, ResultSet rs)
  2. getColunmNames(ResultSetMetaData rsmd)
  3. getIndexColumns(Connection connection, String schema, String table, String indexName)
  4. getIndexName(Connection conn, String table, String column)
  5. getRange(Connection C, String table, String column)
  6. hasColumn(ResultSet rs, String columnName)
  7. hasColumn(ResultSet rs, String columnName)
  8. hasColumn(String columnName, ResultSet resultSet)
  9. hasColumn(String field, ResultSet rs)