Here you can find the source of resultSetContainsColumn(ResultSet rs, String column)
Parameter | Description |
---|---|
rs | The ResultSet to scan |
column | The column to find |
Parameter | Description |
---|---|
SQLException | Thrown in the event of an error whilst processing |
public static boolean resultSetContainsColumn(ResultSet rs, String column) throws SQLException
//package com.java2s; /*/*from w w w . jav a 2 s . c o m*/ * Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute * Copyright [2016-2018] EMBL-European Bioinformatics Institute * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; public class Main { /** * Scans through a result set's metadata in an attempt to find a column * * @param rs * The ResultSet to scan * @param column * The column to find * @return Boolean indicating if there was a column with said name * @throws SQLException * Thrown in the event of an error whilst processing */ public static boolean resultSetContainsColumn(ResultSet rs, String column) throws SQLException { ResultSetMetaData meta = rs.getMetaData(); int total = meta.getColumnCount(); for (int i = 1; i <= total; i++) { if (meta.getColumnName(i).equals(column)) { return true; } } return false; } }