Java SQL Table Column hasColumn(String field, ResultSet rs)

Here you can find the source of hasColumn(String field, ResultSet rs)

Description

Tests if a column exists in the result set.

License

Open Source License

Parameter

Parameter Description
field the label column searched.
rs the result set.

Return

true if the column exists, false otherwise.

Declaration

public static boolean hasColumn(String field, ResultSet rs) throws SQLException 

Method Source Code

//package com.java2s;
/**//from   w  w  w .j  a  va2  s  . co m
 * <p>
 * Utility clas for SQL interface.
 * </p>
 * 
 * <p>
 * &copy; 2004, 2008 StudioGdo/Guillaume Doumenc. All Rights Reserved. This
 * software is the proprietary information of StudioGdo &amp; Guillaume Doumenc.
 * Use is subject to license terms.
 * </p>
 * 
 * 
 * @author Guillaume Doumenc (<a>
 *         href="mailto:gdoumenc@studiogdo.com">gdoumenc@studiogdo.com</a>)
 */

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

public class Main {
    /**
     * Tests if a column exists in the result set.
     * 
     * @param field
     *            the label column searched.
     * @param rs
     *            the result set.
     * @return <tt>true</tt> if the column exists, <tt>false</tt> otherwise.
     */
    public static boolean hasColumn(String field, ResultSet rs) throws SQLException {
        ResultSetMetaData meta = rs.getMetaData();
        int numCol = meta.getColumnCount();

        for (int i = 1; i < numCol + 1; i++) {
            if (meta.getColumnLabel(i).equals(field)) {
                return true;
            }
        }
        return false;
    }
}

Related

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