Java SQL Type toClass(final int type)

Here you can find the source of toClass(final int type)

Description

Translates a data type from an integer (java.sql.Types value) to a class type.

License

Apache License

Parameter

Parameter Description
type The java.sql.Types value to convert to its corresponding class

Return

The class that corresponds to the given java.sql.Types value, or Object.class if the type has no known mapping.

Declaration

public static Class<?> toClass(final int type) 

Method Source Code


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

import java.math.BigDecimal;

import java.sql.Types;

public class Main {
    /**// w  w w. j a v a 2 s  .  c  o  m
     * Translates a data type from an integer (java.sql.Types value) to a class type.
     * 
     * @param type
     *            The java.sql.Types value to convert to its corresponding class
     * @return The class that corresponds to the given java.sql.Types value, or Object.class if the type has no known mapping.
     */
    public static Class<?> toClass(final int type) {
        Class<?> result = null;

        switch (type) {
        case Types.CHAR:
            result = Character.class;
            break;

        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            result = String.class;
            break;

        case Types.NUMERIC:
        case Types.DECIMAL:
            result = BigDecimal.class;
            break;

        case Types.BIT:
            result = Boolean.class;
            break;

        case Types.TINYINT:
            result = Byte.class;
            break;

        case Types.SMALLINT:
            result = Short.class;
            break;

        case Types.INTEGER:
            result = Integer.class;
            break;

        case Types.BIGINT:
            result = Long.class;
            break;

        case Types.REAL:
        case Types.FLOAT:
            result = Float.class;
            break;

        case Types.DOUBLE:
            result = Double.class;
            break;

        case Types.BINARY:
        case Types.VARBINARY:
        case Types.LONGVARBINARY:
            result = Byte[].class;
            break;

        case Types.DATE:
            result = java.sql.Date.class;
            break;

        case Types.TIME:
            result = java.sql.Time.class;
            break;

        case Types.TIMESTAMP:
            result = java.sql.Timestamp.class;
            break;

        default:
            result = Object.class;
            break;
        }

        return result;
    }
}

Related

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