Java SQL ResultSet to convert(int sqlType, String type, ResultSet rs, String name)

Here you can find the source of convert(int sqlType, String type, ResultSet rs, String name)

Description

convert

License

LGPL

Declaration

public static Object convert(int sqlType, String type, ResultSet rs, String name) throws SQLException 

Method Source Code

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

import java.sql.*;

public class Main {
    public static Object convert(int sqlType, String type, ResultSet rs, String name) throws SQLException {
        switch (sqlType) {
        case Types.ARRAY:
            return rs.getArray(name);
        case Types.BIGINT:
            return rs.getLong(name);
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
        case Types.BIT:
            return rs.getBytes(name);
        case Types.BLOB:
            return rs.getBlob(name);
        case Types.BOOLEAN:
            return rs.getBoolean(name);
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            return rs.getString(name);
        case Types.CLOB:
        case Types.NCLOB:
            return rs.getClob(name);
        case Types.DATE:
            return rs.getDate(name);
        case Types.DECIMAL:
        case Types.NUMERIC:
        case Types.FLOAT:
            return rs.getBigDecimal(name);
        case Types.DOUBLE:
        case Types.REAL:
            return rs.getDouble(name);
        case Types.INTEGER:
            return rs.getInt(name);
        case Types.NULL:
            return null;
        case Types.REF:
            return rs.getRef(name);
        case Types.ROWID:
            return rs.getRowId(name);
        case Types.SMALLINT:
            return rs.getShort(name);
        case Types.SQLXML:
            return rs.getSQLXML(name);
        case Types.TIME:
            return rs.getTime(name);
        case Types.TIMESTAMP:
            return rs.getTimestamp(name);
        case Types.TINYINT:
            return rs.getByte(name);
        case Types.JAVA_OBJECT:
        case Types.OTHER:
        case Types.STRUCT:
        default://  w w w  . j  av a2s .c  o m
            throw new SQLException("no conversion found for type '" + type + "'");
        }
    }
}

Related

  1. convert(ResultSet rs)
  2. convertResultSetToJSON(ResultSet resultSet)
  3. convertResultSetToMap(final ResultSet rs)
  4. convertToMap(Map metaData, ResultSet rs)