public static String getValueForColumn ( ResultSet rs , String columnNameToCheck , Database database ) throws SQLException { ResultSetMetaData metadata = rs . getMetaData ( ) ; int numberOfColumns = metadata . getColumnCount ( ) ; String correctedColumnName = database . correctObjectName ( columnNameToCheck , Column . class ) ; // get the column names; column indexes start from 1 for ( int i = 1 ; i < ( numberOfColumns + 1 ) ; i ++ ) { String columnName = metadata . getColumnLabel ( i ) ; // Get the name of the column's table name if ( correctedColumnName . equalsIgnoreCase ( columnName ) ) { return rs . getString ( columnName ) ; } } return null ; }
Checks whether a result set has a column matching the specified column name . The column name is first changed to match the database format . E . g . an unquoted columnName in h2 will be converted to uppercase so the column name that is being checked for is really the uppercase version of the column name