Java SQL ResultSet Read getResultSetValue(ResultSet rs, int index)

Here you can find the source of getResultSetValue(ResultSet rs, int index)

Description

get Result Set Value

License

Apache License

Declaration

public static Object getResultSetValue(ResultSet rs, int index) throws SQLException 

Method Source Code


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

import java.sql.Blob;
import java.sql.Clob;

import java.sql.ResultSet;

import java.sql.SQLException;

public class Main {

    public static Object getResultSetValue(ResultSet rs, int index) throws SQLException {
        Object obj = rs.getObject(index);
        String className = null;//from   w w w  .ja va 2  s  .  c o  m
        if (obj != null) {
            className = obj.getClass().getName();
        }
        if (obj instanceof Blob) {
            obj = rs.getBytes(index);
        } else if (obj instanceof Clob) {
            obj = rs.getString(index);
        } else if (className != null
                && ("oracle.sql.TIMESTAMP".equals(className) || "oracle.sql.TIMESTAMPTZ".equals(className))) {
            obj = rs.getTimestamp(index);
        } else if (className != null && className.startsWith("oracle.sql.DATE")) {
            String metaDataClassName = rs.getMetaData().getColumnClassName(index);
            if ("java.sql.Timestamp".equals(metaDataClassName)
                    || "oracle.sql.TIMESTAMP".equals(metaDataClassName)) {
                obj = rs.getTimestamp(index);
            } else {
                obj = rs.getDate(index);
            }
        } else if (obj != null && obj instanceof java.sql.Date) {
            if ("java.sql.Timestamp".equals(rs.getMetaData().getColumnClassName(index))) {
                obj = rs.getTimestamp(index);
            }
        }
        return obj;
    }
}

Related

  1. getResultSetFromQueryAgainstDefaultConnection( String sql)
  2. getResultSetInstance(Connection conn, String sql)
  3. getResultSetMetaData(ResultSet rs)
  4. getResultSetRowString(ResultSet rs)
  5. getResultSetStrings(ResultSet rs)
  6. getResultSetValue(ResultSet rs, int index)
  7. getResultSetValue(ResultSet rs, int index, Class requiredType)
  8. getResultSetValue(ResultSet rs, int index, Class requiredType)
  9. getReturnCountInt(ResultSet rs, int column)