Java SQL Table Column tableContainsColumn(Connection conn, String table, String column)

Here you can find the source of tableContainsColumn(Connection conn, String table, String column)

Description

Returns true if the table with the specified name exists and contains a column with the specified name, false if either condition does not hold true.

License

Open Source License

Declaration

public static boolean tableContainsColumn(Connection conn, String table, String column) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.Connection;

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

public class Main {
    /**/*  www.  j a v a 2s.  co  m*/
     * Returns true if the table with the specified name exists and contains a column with the
     * specified name, false if either condition does not hold true. <em>Note:</em> the names are
     * case sensitive.
     */
    public static boolean tableContainsColumn(Connection conn, String table, String column) throws SQLException {
        boolean matched = false;
        ResultSet rs = conn.getMetaData().getColumns("", "", table, column);
        while (rs.next()) {
            String tname = rs.getString("TABLE_NAME");
            String cname = rs.getString("COLUMN_NAME");
            if (tname.equals(table) && cname.equals(column)) {
                matched = true;
            }
        }
        return matched;
    }
}

Related

  1. resultSetToOneColumnAsCommamaSeparatedString(ResultSet rs)
  2. resultSetToOneColumnAsList(ResultSet rs)
  3. resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)
  4. resultSetValue(ResultSet resultSet, Class parameterClass, Object object, String columnLabel)
  5. retrieveCoulmns(String tableName, String columnArray[], Statement statement, long offset, long numberOfRecords)
  6. tableContainsIndex(Connection conn, String table, String column, String index)
  7. toColumnNameList(final ResultSet rs)
  8. toFlag(ResultSetMetaData metaData, int column)
  9. toFormatList(ResultSet results, List column)