Java SQL Type getTypeStringForObject(Object o)

Here you can find the source of getTypeStringForObject(Object o)

Description

Gets an SQL Type field string based on the given object.

License

Mozilla Public License

Parameter

Parameter Description
o to test.

Return

String that is a field name in the Types object.

Declaration

public static String getTypeStringForObject(Object o) 

Method Source Code

//package com.java2s;
/*/*ww w. j av  a 2  s  .co  m*/
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
 *
 * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
 * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
 *
 * Contributor(s): 
 *  Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
 *  
 * If you didn't download this code from the following link, you should check
 * if you aren't using an obsolete version: http://www.isqlviewer.com
 */

import java.io.InputStream;
import java.io.Reader;

import java.math.BigDecimal;
import java.math.BigInteger;

import java.sql.Blob;
import java.sql.Clob;
import java.sql.Ref;
import java.sql.Time;
import java.sql.Timestamp;

import java.util.Date;

public class Main {
    /**
     * Gets an SQL Type field string based on the given object.
     * <p>
     * Basically this method gets the field name that can be easily reflected back into the java.sql.Types object to get
     * the integer SQL type that should be used.
     * 
     * @see Types
     * @see #getTypeforValue(int)
     * @param o to test.
     * @return String that is a field name in the Types object.
     */
    public static String getTypeStringForObject(Object o) {

        if (o instanceof String)
            return "VARCHAR";
        if (o instanceof Byte)
            return "TINYINT";
        if (o instanceof Boolean)
            return "BOOLEAN";
        if (o instanceof Short)
            return "SMALLINT";
        if (o instanceof Integer)
            return "INTEGER";
        if (o instanceof Long || o instanceof BigInteger)
            return "BIGINT";
        if (o instanceof Double || o instanceof Float)
            return "DOUBLE";
        if (o instanceof BigDecimal)
            return "DECIMAL";
        if (o instanceof Timestamp)
            return "TIMESTAMP";
        if (o instanceof Time)
            return "TIME";
        if (o instanceof Ref)
            return "REF";
        if (o instanceof Date)
            return "DATE";
        if (o instanceof Clob)
            return "CLOB";
        if (o instanceof Blob)
            return "BLOB";
        if (o instanceof byte[] || o instanceof InputStream)
            return "LONGVARBINARY";
        if (o instanceof Reader)
            return "LONGVARCHAR";
        return "JAVA_OBJECT";
    }
}

Related

  1. getType(int csqltype)
  2. getTypeforValue(int type)
  3. getTypeName(int dataType)
  4. getTypeName(int typeNumber)
  5. getTypeNameForJDBCType(int jdbcType)
  6. getUDTOwner(String typeName, String dbName, Connection conn)
  7. getValueType(String inputValue)
  8. getVarcharTypeString(Connection conn, int length)
  9. getViewIdsForTypes(Connection connection, String... types)