Java SQL Type toJavaType(int sqlType, String type)

Here you can find the source of toJavaType(int sqlType, String type)

Description

to Java Type

License

LGPL

Declaration

public static Class<?> toJavaType(int sqlType, String type) throws SQLException 

Method Source Code

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

import java.math.*;
import java.sql.*;
import java.sql.Array;
import java.sql.Date;

public class Main {
    public static Class<?> toJavaType(int sqlType, String type) throws SQLException {
        switch (sqlType) {
        case Types.ARRAY:
            return Array.class;
        case Types.BIGINT:
            return Long.class;
        case Types.BINARY:
        case Types.LONGVARBINARY:
        case Types.VARBINARY:
        case Types.BIT:
            return Byte[].class;
        case Types.BLOB:
            return Blob.class;
        case Types.BOOLEAN:
            return Boolean.class;
        case Types.CHAR:
        case Types.LONGNVARCHAR:
        case Types.LONGVARCHAR:
        case Types.NCHAR:
        case Types.NVARCHAR:
        case Types.VARCHAR:
            return String.class;
        case Types.CLOB:
        case Types.NCLOB:
            return Clob.class;
        case Types.DATE:
            return Date.class;
        case Types.DECIMAL:
        case Types.NUMERIC:
        case Types.FLOAT:
            return BigDecimal.class;
        case Types.DOUBLE:
        case Types.REAL:
            return Double.class;
        case Types.INTEGER:
            return Integer.class;
        case Types.NULL:
            return null;
        case Types.REF:
            return Ref.class;
        case Types.ROWID:
            return RowId.class;
        case Types.SMALLINT:
            return Short.class;
        case Types.SQLXML:
            return SQLXML.class;
        case Types.TIME:
            return Time.class;
        case Types.TIMESTAMP:
            return Timestamp.class;
        case Types.TINYINT:
            return Byte.class;
        case Types.JAVA_OBJECT:
        case Types.OTHER:
        case Types.STRUCT:
        default://from  ww  w.  j  av a 2  s  .  c om
            throw new SQLException("no conversion found for type '" + type + "'");
        }
    }
}

Related

  1. sqlTypeToSetterGetter(int sqlType)
  2. sqlTypeToSqlTypeName(final int type)
  3. toClass(final int type)
  4. toClass(int sqlType, boolean isUnsigned)
  5. toHCatType(int sqlType)
  6. toOdaDataType(Class odiTypeClass)
  7. toSqlType(Class clazz)
  8. toSqlType(String clickshouseType)
  9. toSqlType(String clickshouseType)