Java SQL ResultSet Read getValueByObjectType(ResultSetMetaData metaData, ResultSet rs, int index)

Here you can find the source of getValueByObjectType(ResultSetMetaData metaData, ResultSet rs, int index)

Description

get Value By Object Type

License

Apache License

Declaration

public static Object getValueByObjectType(ResultSetMetaData metaData, ResultSet rs, int index)
        throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

import java.sql.Types;

public class Main {

    public static Object getValueByObjectType(ResultSetMetaData metaData, ResultSet rs, int index)
            throws Exception {
        int columnIndex = index + 1;
        Object return_obj = rs.getObject(columnIndex);
        if (return_obj != null) {
            int type = metaData.getColumnType(columnIndex);
            switch (type) {
            case Types.BIT:
                return_obj = rs.getByte(columnIndex);
                break;
            case Types.TINYINT:
                return_obj = rs.getByte(columnIndex);
                break;
            case Types.SMALLINT:
                return_obj = rs.getShort(columnIndex);
                break;
            case Types.LONGVARBINARY:
                return_obj = rs.getBytes(columnIndex);
                break;
            case Types.BLOB:
                return_obj = rs.getBytes(columnIndex);
                break;
            default:
                return_obj = rs.getObject(columnIndex);
            }//from w  ww.j  a  v a2  s  . c  om
        }
        return return_obj;
    }
}

Related

  1. getValue(int type, ResultSet resultSet, int columnIndex)
  2. getValue(ResultSet result, String strField)
  3. getValue(ResultSet resultSet, String columnName, E defaultValue)
  4. getValue(ResultSet rs, String sField)
  5. getValue4Type(ResultSet rs, String column, Class typeClass)
  6. getValueFromResultSet(int index, final ResultSet resultSet, final Class type)
  7. readBitBoolean(ResultSet result, int index)
  8. readBytes(ResultSet rs, int pos)
  9. readDate(ResultSet result, int index)