Java SQL Table Column lookupColumnIndex(ResultSetMetaData resultSetMetaData, String name)

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

Description

lookup Column Index

License

Open Source License

Parameter

Parameter Description
resultSetMetaData a parameter
columnName the SQL name of the column

Return

the index of the matching column name

Declaration

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

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010 s IT Solutions AT Spardat GmbH . All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * //from   ww  w.java  2s . co m
 * Contributors: s IT Solutions AT Spardat GmbH - initial API and implementation
 *******************************************************************************/

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

public class Main {
    /**
     * @return the index of the matching column name
     * @param resultSetMetaData
     * @param columnName
     *            the SQL name of the column
     */
    public static int lookupColumnIndex(ResultSetMetaData resultSetMetaData, String name) throws SQLException {
        int columnCount = resultSetMetaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            String columnName = resultSetMetaData.getColumnName(i);
            if (columnName.equals(name)) {
                return i;
            }
        }
        return -1;
    }
}

Related

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