Java SQL ResultSet Read getFirstGeometryFieldIndex(ResultSet resultSet)

Here you can find the source of getFirstGeometryFieldIndex(ResultSet resultSet)

Description

Find the first geometry field name of a resultSet.

License

Open Source License

Parameter

Parameter Description
resultSet a parameter

Exception

Parameter Description
SQLException an exception

Return

The index of first Geometry field

Declaration

public static int getFirstGeometryFieldIndex(ResultSet resultSet)
        throws SQLException 

Method Source Code

//package com.java2s;
/*/*  w  w w . j a  v a2  s . c  o  m*/
 * h2spatial is a library that brings spatial support to the H2 Java database.
 *
 * h2spatial is distributed under GPL 3 license. It is produced by the "Atelier SIG"
 * team of the IRSTV Institute <http://www.irstv.fr/> CNRS FR 2488.
 *
 * Copyright (C) 2007-2014 IRSTV (FR CNRS 2488)
 *
 * h2patial is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * h2spatial is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * h2spatial. If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, please consult: <http://www.orbisgis.org/>
 * or contact directly:
 * info_at_ orbisgis.org
 */

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

public class Main {
    /**
     * Find the first geometry field name of a resultSet. Return -1 if there is
     * no geometry column
     *
     * @param resultSet
     * @return The index of first Geometry field
     * @throws SQLException
     */
    public static int getFirstGeometryFieldIndex(ResultSet resultSet)
            throws SQLException {
        ResultSetMetaData meta = resultSet.getMetaData();
        int columnCount = meta.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            if (meta.getColumnTypeName(i).equalsIgnoreCase("geometry")) {
                return i;
            }
        }
        return -1;
    }
}

Related

  1. getEnumFromResultSet(ResultSet rset, Enum field, T[] enumValues)
  2. getExpectedType(ResultSet resultSet, int columnIndex)
  3. getExplainPlan(ResultSet rs)
  4. getFieldNames(ResultSet rs)
  5. getFieldsPresentInResultSet(ResultSet rs)
  6. getFirstInt(ResultSet resultSet)
  7. getFlags(ResultSet rs)
  8. getGeneratedIdFromResultSet(ResultSet resultSet)
  9. getHashMap(ResultSet resultSet)