Java SQL Type getClassByJdbcType(int type, int decimalDigits)

Here you can find the source of getClassByJdbcType(int type, int decimalDigits)

Description

get Class By Jdbc Type

License

Open Source License

Declaration

public static Class getClassByJdbcType(int type, int decimalDigits) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2000-2003 The Software Conservancy as Trustee.
 * All rights reserved./*from  ww w .  java2  s  . c  o m*/
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Nothing in this notice shall be deemed to grant any rights to trademarks,
 * copyrights, patents, trade secrets or any other intellectual property of the
 * licensor or any contributor except as expressly stated herein. No patent
 * license is granted separate from the Software, for code that you delete from
 * the Software, or for combinations of the Software with other software or
 * hardware.
 */

import java.sql.*;

public class Main {
    public static Class getClassByJdbcType(int type, int decimalDigits) {
        switch (type) {
        case Types.CHAR:
        case Types.VARCHAR:
        case Types.LONGVARCHAR:
            return String.class;

        case Types.BIT:
        case Types.BOOLEAN:
            return Boolean.class;

        case Types.TINYINT:
        case Types.SMALLINT:
        case Types.INTEGER:
            return Integer.class;

        case Types.BIGINT:
            return Long.class;

        case Types.FLOAT:
        case Types.DOUBLE:
            return Double.class;

        case Types.DECIMAL:
        case Types.NUMERIC:
            if (decimalDigits == 0) {
                return Long.class;
            } else {
                return Double.class;
            }

        case Types.DATE:
            return java.sql.Date.class;

        case Types.TIME:
        case Types.TIMESTAMP:
            return java.util.Date.class;

        default:
            return String.class;
        }
    }
}

Related

  1. getBIRTDataType(Integer datatype)
  2. getCallableStatementValue(CallableStatement cstm, int index)
  3. getCastExpression(Class aClass)
  4. getCharStream(Object value, int columnType)
  5. getClass(int sqlType, int precision, int scale)
  6. getCloverTypeFromJdbcType(int jdbcDataType)
  7. getColumeTypeDesc(Class clazz)
  8. getColumnClass(int sqlType)
  9. getColumnType(Connection conn, String table, String column)