Java SQL Type getJDBCTypeName(int value)

Here you can find the source of getJDBCTypeName(int value)

Description

get JDBC Type Name

License

Open Source License

Declaration

public static String getJDBCTypeName(int value) 

Method Source Code


//package com.java2s;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

public class Main {
    static Map<Object, String> jdbcTypeValues;

    public static String getJDBCTypeName(int value) {
        if (jdbcTypeValues == null) {
            jdbcTypeValues = new HashMap<Object, String>();
            Field[] fields = Types.class.getFields();
            for (int i = 0; i < fields.length; i++) {
                Field field = fields[i];
                if (Modifier.isStatic(field.getModifiers())) {
                    try {
                        jdbcTypeValues.put(field.get(Types.class), field.getName());
                    } catch (IllegalArgumentException e) {
                        // ignore                  
                    } catch (IllegalAccessException e) {
                        // ignore               
                    }//w w w.j  a v a 2  s .  com
                }
            }
        }

        String name = (String) jdbcTypeValues.get(new Integer(value));

        if (name != null) {
            return name;
        } else {
            return "" + value; //$NON-NLS-1$
        }
    }
}

Related

  1. getJdbcType(String datatype)
  2. getJdbcType(String typeName)
  3. getJdbcTypeClass(int type)
  4. getJDBCTypeForNamedType(String aTypeName)
  5. getJdbcTypeName(int jdbcType)
  6. getJdbcTypeNames()
  7. getJDBCTypes()
  8. getLength(String format, String columnTypeName)
  9. getLong(Object object)