Java SQL Type typeToClass(int type)

Here you can find the source of typeToClass(int type)

Description

Returns the class associated with a SQL type.

License

Open Source License

Parameter

Parameter Description
type the SQL type

Return

the Java class corresponding with the type

Declaration

public static Class<?> typeToClass(int type) 

Method Source Code

//package com.java2s;
/*//from  w w  w. j av  a2  s  .c om
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.sql.Types;

public class Main {
    /**
     * Returns the class associated with a SQL type.
     * 
     * @param type the SQL type
     * @return the Java class corresponding with the type
     */
    public static Class<?> typeToClass(int type) {
        Class<?> result;

        switch (type) {
        case Types.BIGINT:
            result = Long.class;
            break;
        case Types.BINARY:
            result = String.class;
            break;
        case Types.BIT:
            result = Boolean.class;
            break;
        case Types.CHAR:
            result = Character.class;
            break;
        case Types.DATE:
            result = java.sql.Date.class;
            break;
        case Types.DECIMAL:
            result = Double.class;
            break;
        case Types.DOUBLE:
            result = Double.class;
            break;
        case Types.FLOAT:
            result = Float.class;
            break;
        case Types.INTEGER:
            result = Integer.class;
            break;
        case Types.LONGVARBINARY:
            result = String.class;
            break;
        case Types.LONGVARCHAR:
            result = String.class;
            break;
        case Types.NULL:
            result = String.class;
            break;
        case Types.NUMERIC:
            result = Double.class;
            break;
        case Types.OTHER:
            result = String.class;
            break;
        case Types.REAL:
            result = Double.class;
            break;
        case Types.SMALLINT:
            result = Short.class;
            break;
        case Types.TIME:
            result = java.sql.Time.class;
            break;
        case Types.TIMESTAMP:
            result = java.sql.Timestamp.class;
            break;
        case Types.TINYINT:
            result = Short.class;
            break;
        case Types.VARBINARY:
            result = String.class;
            break;
        case Types.VARCHAR:
            result = String.class;
            break;
        default:
            result = null;
        }

        return result;
    }
}

Related

  1. toSqlType(String clickshouseType)
  2. toSqlType(String clickshouseType)
  3. translateType(int sqlType)
  4. typeName(int type)
  5. typeNameToValueType(String typeName)
  6. typeToString(int sqlType)
  7. writeObject(Object obj, int sqlType, DataOutput out)