Java SQL Table Column resultSetValue(ResultSet resultSet, Class parameterClass, Object object, String columnLabel)

Here you can find the source of resultSetValue(ResultSet resultSet, Class parameterClass, Object object, String columnLabel)

Description

result Set Value

License

Open Source License

Declaration

private static Object resultSetValue(ResultSet resultSet, Class<?> parameterClass, Object object,
            String columnLabel) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Date;

public class Main {
    private static Object resultSetValue(ResultSet resultSet, Class<?> parameterClass, Object object,
            String columnLabel) throws SQLException {
        Object value = null;//w  w w .  j a v  a2s .  c om
        if (parameterClass.equals(String.class)) {
            value = resultSet.getString(columnLabel);
        } else if (parameterClass.equals(Integer.class)) {
            value = resultSet.getInt(columnLabel);
        } else if (parameterClass.equals(Float.class)) {
            value = resultSet.getFloat(columnLabel);
        } else if (parameterClass.equals(Long.class)) {
            value = resultSet.getLong(columnLabel);
        } else if (parameterClass.equals(Double.class)) {
            value = resultSet.getDouble(columnLabel);
        } else if (parameterClass.equals(Short.class)) {
            value = resultSet.getShort(columnLabel);
        } else if (parameterClass.equals(Date.class)) {
            value = resultSet.getTimestamp(columnLabel);
        } else if (parameterClass.equals(BigDecimal.class)) {
            value = resultSet.getBigDecimal(columnLabel);
        } else {
            value = object;
        }
        return value;
    }

    private static Object resultSetValue(ResultSet resultSet, Class<?> parameterClass, Object object,
            Integer columnIndex) throws SQLException {
        Object value = null;
        if (parameterClass.equals(String.class)) {
            value = resultSet.getString(columnIndex);
        } else if (parameterClass.equals(Integer.class)) {
            value = resultSet.getInt(columnIndex);
        } else if (parameterClass.equals(Float.class)) {
            value = resultSet.getFloat(columnIndex);
        } else if (parameterClass.equals(Long.class)) {
            value = resultSet.getLong(columnIndex);
        } else if (parameterClass.equals(Double.class)) {
            value = resultSet.getDouble(columnIndex);
        } else if (parameterClass.equals(Short.class)) {
            value = resultSet.getShort(columnIndex);
        } else if (parameterClass.equals(Date.class)) {
            value = resultSet.getTimestamp(columnIndex);
        } else if (parameterClass.equals(BigDecimal.class)) {
            value = resultSet.getBigDecimal(columnIndex);
        } else {
            value = object;
        }
        return value;
    }
}

Related

  1. resultSetContainsColumn(ResultSet rs, String column)
  2. resultSetHasColumn(ResultSet rs, String sColumnName)
  3. resultSetToOneColumnAsCommamaSeparatedString(ResultSet rs)
  4. resultSetToOneColumnAsList(ResultSet rs)
  5. resultSetToStringFormat(ResultSet rs, String separator, String quote, boolean column)
  6. retrieveCoulmns(String tableName, String columnArray[], Statement statement, long offset, long numberOfRecords)
  7. tableContainsColumn(Connection conn, String table, String column)
  8. tableContainsIndex(Connection conn, String table, String column, String index)
  9. toColumnNameList(final ResultSet rs)