Java SQL Type getJavaType(int dataType, int columnSize, int decimalDegit)

Here you can find the source of getJavaType(int dataType, int columnSize, int decimalDegit)

Description

get Java Type

License

Apache License

Declaration

public static String getJavaType(int dataType, int columnSize, int decimalDegit) 

Method Source Code

//package com.java2s;
/*//from  ww  w  . j av a  2  s .co m
 * Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.sql.Types;

import java.util.Date;

public class Main {
    public static String getJavaType(int dataType, int columnSize, int decimalDegit) {
        String fieldType = String.class.getName();

        switch (dataType) {
        case Types.ARRAY:
            break;
        case Types.BIGINT:
            fieldType = "long";
            break;
        case Types.BINARY:
            break;
        case Types.BIT:
            break;
        case Types.BLOB:
            break;
        case Types.BOOLEAN:
            fieldType = "boolean";
            break;
        case Types.CHAR:
            break;
        case Types.CLOB:
            break;
        case Types.DATALINK:
            break;
        case Types.DATE:
            fieldType = Date.class.getName();
            break;
        case Types.DECIMAL:
            if (decimalDegit > 0) {
                fieldType = "double";
            } else {
                fieldType = "int";
            }
            break;
        case Types.DISTINCT:
            break;
        case Types.DOUBLE:
            fieldType = "double";
            break;
        case Types.FLOAT:
            fieldType = "float";
            break;
        case Types.INTEGER:
            fieldType = "int";
            break;
        case Types.JAVA_OBJECT:
            break;
        case Types.LONGVARBINARY:
            break;
        case Types.LONGVARCHAR:
            break;
        case Types.NULL:
            break;
        case Types.NUMERIC:
            if (decimalDegit > 0) {
                fieldType = "double";
            } else {
                fieldType = "int";
            }
            break;
        case Types.OTHER:
            break;
        case Types.REAL:
            break;
        case Types.REF:
            break;
        case Types.SMALLINT:
            fieldType = "int";
            break;
        case Types.STRUCT:
            break;
        case Types.TIME:
            fieldType = Date.class.getName();
            break;
        case Types.TIMESTAMP:
            fieldType = Date.class.getName();
            break;
        case Types.TINYINT:
            fieldType = "int";
            break;
        case Types.VARBINARY:
            break;
        case Types.VARCHAR:
            break;
        default:
            break;
        }

        return fieldType;
    }
}

Related

  1. getExpressionChoices(int type)
  2. getFormatTypeAsString(int fieldType)
  3. getInsertarEmpresa()
  4. getIntTypeString(Connection conn)
  5. getIntValue(String typeName)
  6. getJavaType(int jdbcType)
  7. getJavaType(int sqlType)
  8. getJavaType(String rdbType)
  9. getJavaTypeFromSqlType(int sqlType)