Java SQL Type toClass(int sqlType, boolean isUnsigned)

Here you can find the source of toClass(int sqlType, boolean isUnsigned)

Description

to Class

License

Apache License

Declaration

public static Class toClass(int sqlType, boolean isUnsigned)
            throws SQLException 

Method Source Code

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

import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;

public class Main {
    public static Class toClass(int sqlType, boolean isUnsigned)
            throws SQLException {
        return toClass(sqlType, -1, isUnsigned);
    }//from   w  w  w.j a  v  a 2  s . co  m

    public static Class toClass(int sqlType, int elementSqltype,
            boolean isUnsigned) throws SQLException {
        switch (sqlType) {
        case Types.BIT:
        case Types.BOOLEAN:
            return Boolean.class;
        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            if (isUnsigned)
                return Long.class;
            return Integer.class;
        case Types.BIGINT:
            if (isUnsigned)
                return BigInteger.class;
            return Long.class;
        case Types.DOUBLE:
            return Double.class;
        case Types.NUMERIC:
        case Types.DECIMAL:
            return BigDecimal.class;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
        case Types.BLOB:
            return String.class;
        case Types.FLOAT:
        case Types.REAL:
            return Float.class;
        case Types.DATE:
            return java.sql.Date.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        case Types.TIME:
            return Time.class;
        case Types.ARRAY:
            Class elementType = toClass(elementSqltype, isUnsigned);
            return Array.newInstance(elementType, 0).getClass();
        default:
            throw new UnsupportedOperationException("Sql type " + sqlType
                    + "is not supported");
        }
    }
}

Related

  1. sqlTypeToClassType(final Integer sqlType)
  2. sqlTypeToHiveType(Integer type)
  3. sqlTypeToSetterGetter(int sqlType)
  4. sqlTypeToSqlTypeName(final int type)
  5. toClass(final int type)
  6. toHCatType(int sqlType)
  7. toJavaType(int sqlType, String type)
  8. toOdaDataType(Class odiTypeClass)
  9. toSqlType(Class clazz)