Here you can find the source of hasColumn(String field, ResultSet rs)
Parameter | Description |
---|---|
field | the label column searched. |
rs | the result set. |
public static boolean hasColumn(String field, ResultSet rs) throws SQLException
//package com.java2s; /**//from w w w .j a va2 s . co m * <p> * Utility clas for SQL interface. * </p> * * <p> * © 2004, 2008 StudioGdo/Guillaume Doumenc. All Rights Reserved. This * software is the proprietary information of StudioGdo & 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; } }