Java SQL Table Column resultSetHasColumn(ResultSet rs, String sColumnName)

Here you can find the source of resultSetHasColumn(ResultSet rs, String sColumnName)

Description

Determines if a column exists within the given resultset

License

Open Source License

Parameter

Parameter Description
rs a parameter
sColumnName a parameter

Return

true if the column exists. Case insensitive

Declaration

public static boolean resultSetHasColumn(ResultSet rs, String sColumnName) throws Exception 

Method Source Code

//package com.java2s;
/** ***************************************************************
Util.java// w w w  . j a  v  a  2 s  .c  o m
Copyright (C) 2001  Brendon Upson 
http://www.wnc.net.au info@wnc.net.au
    
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    
 *************************************************************** */

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

public class Main {
    /**
     * Determines if a column exists within the given resultset
     * @param rs
     * @param sColumnName
     * @return true if the column exists. Case insensitive
     */
    public static boolean resultSetHasColumn(ResultSet rs, String sColumnName) throws Exception {
        if (rs == null)
            return false;
        ResultSetMetaData rsmd = rs.getMetaData();
        int iCols = rsmd.getColumnCount();
        for (int i = 1; i <= iCols; i++) //cols count 1 through n
        {
            if (rsmd.getColumnName(i).equalsIgnoreCase(sColumnName))
                return true;
        }
        return false;
    }
}

Related

  1. readMultiDouble(ResultSet resultSet, String columnName)
  2. readString(final ResultSet resultSet, final String columnName)
  3. readStringFromBlob(ResultSet resultSet, String columnLabel)
  4. resultSetAsCount(ResultSet rs, String countColumn)
  5. resultSetContainsColumn(ResultSet rs, String column)
  6. resultSetToOneColumnAsCommamaSeparatedString(ResultSet rs)
  7. resultSetToOneColumnAsList(ResultSet rs)
  8. resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)
  9. resultSetValue(ResultSet resultSet, Class parameterClass, Object object, String columnLabel)