Java SQL Type getSqlTypeByValue(Object value)

Here you can find the source of getSqlTypeByValue(Object value)

Description

Finds appropriate SQL type for the given value.

License

Open Source License

Parameter

Parameter Description
value a parameter

Declaration

public static int getSqlTypeByValue(Object value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.sql.Types;

public class Main {
    /**/*from w  w w.  j av  a  2  s.c om*/
     * Finds appropriate SQL type for the given value.
     * Returns Types.OTHER if not found.
     * 
     * @param value
     * @return
     */
    public static int getSqlTypeByValue(Object value) {
        if (value instanceof Integer) {
            return Types.INTEGER;
        } else if (value instanceof java.math.BigDecimal) {
            return Types.NUMERIC;
        } else if (value instanceof String) {
            return Types.VARCHAR;
        } else if (value instanceof Byte) {
            return Types.TINYINT;
        } else if (value instanceof Short) {
            return Types.SMALLINT;
        } else if (value instanceof Long) {
            return Types.BIGINT;
        } else if (value instanceof Float) {
            return Types.REAL;
        } else if (value instanceof Double) {
            return Types.DOUBLE;
        } else if (value instanceof byte[]) {
            return Types.VARBINARY;
        } else if (value instanceof java.sql.Date) {
            return Types.DATE;
        } else if (value instanceof java.sql.Time) {
            return Types.TIME;
        } else if (value instanceof java.sql.Timestamp) {
            return Types.TIMESTAMP;
        } else if (value instanceof Boolean) {
            return Types.BIT;
        } else if (value instanceof java.sql.Struct) {
            return Types.STRUCT;
        } else {
            return Types.OTHER;
        }
    }
}

Related

  1. getSqlType(String cubridType)
  2. getSQLType(String text)
  3. getSQLType(String type)
  4. getSqlTypeAsString(int jdbcType)
  5. getSQLTypeByName(String type)
  6. getSqlTypeName(int sqlType)
  7. getSQLTypeName(int sqlType)
  8. getSQLTypeName(int sqlType)
  9. getSqlTypeName(int type)