Java SQL Table Column lookupColumnIndex(final ResultSetMetaData resultSetMetaData, final String columnName)

Here you can find the source of lookupColumnIndex(final ResultSetMetaData resultSetMetaData, final String columnName)

Description

lookup Column Index

License

Apache License

Declaration

public static int lookupColumnIndex(final ResultSetMetaData resultSetMetaData, final String columnName)
            throws SQLException 

Method Source Code

//package com.java2s;
/**//  ww  w .  j av  a2s.c  o m
 * Licensed under the Apache License, Version 2.0
 * 
 * @author ??(cknet@126.com, 13910090885)
 *         https://github.com/simpleframework
 *         http://www.simpleframework.net
 */

import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class Main {
    public static int lookupColumnIndex(final ResultSetMetaData resultSetMetaData, final String columnName)
            throws SQLException {
        if (columnName != null) {
            for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
                if (columnName.equalsIgnoreCase(lookupColumnName(resultSetMetaData, i))) {
                    return i;
                }
            }
        }
        return 0;
    }

    public static String lookupColumnName(final ResultSetMetaData resultSetMetaData, final int columnIndex)
            throws SQLException {
        String name = resultSetMetaData.getColumnLabel(columnIndex);
        if (name == null || name.length() < 1) {
            name = resultSetMetaData.getColumnName(columnIndex);
        }
        return name;
    }
}

Related

  1. hasTableAndColumns(Connection conn, String tableName, String... colNames)
  2. indent_DisplayBanner(PrintWriter out, ResultSetMetaData rsmd, int indentLevel, int[] displayColumns, int[] displayColumnWidths)
  3. isColumnNullable(Connection conn, String table, String column)
  4. isColumnNullable(Connection conn, String table, String column)
  5. isNull(ResultSet resultSet, String columnName)
  6. lookupColumnIndex(ResultSetMetaData resultSetMetaData, String name)
  7. lookupColumnName(ResultSetMetaData resultSetMetaData, int columnIndex)
  8. printTableColumn(Connection conn, String sql)
  9. readMultiDouble(ResultSet resultSet, String columnName)