Java SQL ResultSet extractIntResult(ResultSet rs, ResultSetMetaData rsmd, int index)

Here you can find the source of extractIntResult(ResultSet rs, ResultSetMetaData rsmd, int index)

Description

This method returns an int result at a given index.

License

Open Source License

Parameter

Parameter Description
stmt Statement that has been successfully executed
index Index of expected column

Exception

Parameter Description
Exception If there is no column at index

Return

A value returned at the specified index

Declaration

static public int extractIntResult(ResultSet rs, ResultSetMetaData rsmd, int index) throws Exception 

Method Source Code


//package com.java2s;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

public class Main {
    /**//from   w  w  w .j a v a  2 s  .c om
     * This method returns an int result at a given index. 
     * @param stmt Statement that has been successfully executed
     * @param index Index of expected column
     * @return A value returned at the specified index
     * @throws Exception If there is no column at index 
     */
    static public int extractIntResult(ResultSet rs, ResultSetMetaData rsmd, int index) throws Exception {

        int count = rsmd.getColumnCount();
        if (index > count || index < 1) {
            throw new Exception("Invalid index");
        }

        int type = rsmd.getColumnType(index);
        switch (type) {
        case java.sql.Types.INTEGER:
        case java.sql.Types.SMALLINT:
            return rs.getInt(index);
        }

        throw new Exception("Column type (" + type + ") invalid for a string at index: " + index);
    }
}

Related

  1. createLargeResultSetStatement(Connection conn)
  2. createTable(ResultSet rs)
  3. createUid(final String[] keys, final ResultSet rs, final String keySeparator)
  4. encodeHeader(ResultSetMetaData metaData)
  5. extractGeneratedId(ResultSet generatedKeys)
  6. extractResults(ResultSet resultSet)
  7. extractResultSetFiledNames(ResultSet result)
  8. fillRowNames(Map metaData, ResultSet rs)
  9. hasCompleted(ResultSet rs)