Here you can find the source of lookupColumnIndex(ResultSetMetaData resultSetMetaData, String name)
Parameter | Description |
---|---|
resultSetMetaData | a parameter |
columnName | the SQL name of the column |
public static int lookupColumnIndex(ResultSetMetaData resultSetMetaData, String name) throws SQLException
//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; } }