Java SQL Type getObjectType(Object param)

Here you can find the source of getObjectType(Object param)

Description

get Object Type

License

Apache License

Declaration

public static final int getObjectType(Object param) 

Method Source Code


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

import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Types;

import java.util.Date;

public class Main {
    public static final int getObjectType(Object param) {
        if (param instanceof Integer) {
            return Types.INTEGER;
        } else if (param instanceof String) {
            return Types.VARCHAR;
        } else if (param instanceof Double) {
            return Types.DOUBLE;
        } else if (param instanceof Float) {
            return Types.FLOAT;
        } else if (param instanceof BigInteger) {
            return Types.BIGINT;
        } else if (param instanceof Long) {
            return Types.BIGINT;
        } else if (param instanceof Boolean) {
            return Types.BOOLEAN;
        } else if (param instanceof Date) {
            return Types.DATE;
        } else if (param instanceof BigDecimal) {
            return Types.NUMERIC;
        } else {//from w w  w  .j a v  a2s .  c  o m
            return Types.VARCHAR;
        }
    }

    public static final int getObjectType(String typeName) {
        if (typeName == null) {
            return Types.VARCHAR;
        }
        // int type = Types.VARCHAR;
        if (typeName.equalsIgnoreCase("int") || typeName.equalsIgnoreCase("integer")) {
            return Types.INTEGER;
        } else if (typeName.equalsIgnoreCase("tinyint")) {
            return Types.TINYINT;
        } else if (typeName.equalsIgnoreCase("smallint")) {
            return Types.SMALLINT;
        } else if (typeName.equalsIgnoreCase("mediumint")) {
            return Types.INTEGER;
        } else if (typeName.equalsIgnoreCase("decimal") || typeName.equalsIgnoreCase("numberic")) {
            return Types.DOUBLE;
        } else if (typeName.equalsIgnoreCase("float") || typeName.equalsIgnoreCase("real")) {
            return Types.FLOAT;
        } else if (typeName.equalsIgnoreCase("bigint")) {
            return Types.BIGINT;
        } else if (typeName.equalsIgnoreCase("varchar")) {
            return Types.VARCHAR;
        } else if (typeName.equalsIgnoreCase("char")) {
            return Types.CHAR;
            // } else if (param instanceof Long) {
            // return Types.BIGINT;
        } else if (typeName.equalsIgnoreCase("bit")) {
            return Types.BOOLEAN;
        } else if (typeName.equalsIgnoreCase("datetime")) {
            return Types.DATE;
        } else if (typeName.equalsIgnoreCase("date")) {
            return Types.DATE;
        } else if (typeName.equalsIgnoreCase("time")) {
            return Types.TIME;
        } else if (typeName.equalsIgnoreCase("timestamp")) {
            return Types.TIMESTAMP;
            // } else if (param instanceof BigDecimal) {
            // return Types.NUMERIC;
        } else {
            return Types.VARCHAR;
        }
    }
}

Related

  1. getNameFromJdbcType(int jdbcType)
  2. getNextQuotes(String lastQuotes, int lastType)
  3. getNumberType(Integer precision, Integer scale)
  4. getNumTypeWidth(int type)
  5. getObject(int sqlType, String value)
  6. getObjectType(Object param)
  7. getOdaTypeName(int odaTypeCode)
  8. getParamArray(String signature, int numParam, boolean returnAllParams)
  9. getPartitionSizeValidationError(int colType, String column, String partitionSize)