Java SQL ResultSet Read getObject(ResultSet set, int columnIndex)

Here you can find the source of getObject(ResultSet set, int columnIndex)

Description

Get Object by special column index

License

Open Source License

Parameter

Parameter Description
set a parameter
columnIndex a parameter

Exception

Parameter Description
SQLException an exception

Declaration

public static Object getObject(ResultSet set, int columnIndex) throws SQLException 

Method Source Code

//package com.java2s;
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt

import java.sql.ResultSet;

import java.sql.SQLException;

public class Main {
    private static final String NULLDATE = "0000-00-00 00:00:00";

    /**/* www . j  av a2  s  . c  om*/
     * 
     * Get Object by special column index
     * 
     * @param set
     * @param columnIndex
     * @return
     * @throws SQLException
     */
    public static Object getObject(ResultSet set, int columnIndex) throws SQLException {
        Object object = null;
        try {
            object = set.getObject(columnIndex);
        } catch (SQLException e) {
            if (NULLDATE.equals(set.getString(columnIndex))) {
                object = null;
            } else {
                throw e;
            }

        }
        return object;
    }

    /**
     * 
     * Get Object by special column name
     * 
     * @param set
     * @param columnName
     * @return
     * @throws SQLException
     */
    public static Object getObject(ResultSet set, String columnName) throws SQLException {
        Object object = null;
        try {
            object = set.getObject(columnName);
        } catch (SQLException e) {
            if (NULLDATE.equals(set.getString(columnName))) {
                object = null;
            } else {
                throw e;
            }

        }
        return object;
    }
}

Related

  1. getNumber(ResultSet rs, String name)
  2. getNumberColumns(ResultSet rs)
  3. getNumRows(ResultSet query)
  4. getObject(ResultSet resultSet, int columnCount, Map columnLabelMap, String[] fields, String[] columnLabel, Class cls, Boolean flag)
  5. getObject(ResultSet rs, int columnIndex, Class type)
  6. getObjectByTypeCoercion(ResultSet resultSet, int index, int dataType)
  7. getOjbClassName(ResultSet rs)
  8. getOptionalInt(ResultSet rs, String name)
  9. getPath(ResultSet r, String columnName)