get Java Class For Sql Type - Java JDBC

Java examples for JDBC:JDBC Types

Description

get Java Class For Sql Type

Demo Code


//package com.java2s;

import java.sql.Types;

public class Main {
    public static Class getJavaClassForSqlType(int type) {
        Class clazz = null;//ww  w. java2s.  com
        switch (type) {
        case Types.SMALLINT:
            clazz = java.lang.Short.class;
            break;
        case Types.INTEGER:
            clazz = java.lang.Integer.class;
            break;
        case Types.DECIMAL:
            clazz = java.math.BigDecimal.class;
            break;
        case Types.BIGINT:
            clazz = java.lang.Long.class;
            break;
        case Types.REAL:
            clazz = java.lang.Float.class;
            break;
        case Types.DOUBLE:
            clazz = java.lang.Double.class;
            break;
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.BLOB:
            clazz = java.lang.String.class;
            break;
        case Types.DATE:
            clazz = java.sql.Date.class;
            break;
        case Types.TIME:
            clazz = java.sql.Time.class;
            break;
        case Types.TIMESTAMP:
            clazz = java.sql.Timestamp.class;
            break;
        case Types.NUMERIC:
            clazz = java.lang.Long.class;
            break;

        default:
            clazz = java.lang.String.class;
            break;
        }
        return clazz;
    }
}

Related Tutorials