Java SQL Type getJdbcTypeName(int jdbcType)

Here you can find the source of getJdbcTypeName(int jdbcType)

Description

get Jdbc Type Name

License

Open Source License

Declaration

public static String getJdbcTypeName(int jdbcType) 

Method Source Code


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

import java.lang.reflect.Field;

import java.util.HashMap;

import java.util.Map;
import org.apache.log4j.Logger;

public class Main {
    private static Logger logger = Logger.getLogger("DBUtils");
    private static Map map;

    public static String getJdbcTypeName(int jdbcType) {
        // Use reflection to populate a map of int values to names
        if (map != null)
            return (String) map.get(new Integer(jdbcType));

        map = new HashMap();

        // Get all field in java.sql.Types
        Field[] fields = java.sql.Types.class.getFields();
        for (int i = 0; i < fields.length; i++) {
            try {
                // Get field name and value
                String name = fields[i].getName();
                Integer value = (Integer) fields[i].get(null);
                // Add to map
                map.put(value, name);//w  w  w  .jav  a2  s  .  c  om
            } catch (IllegalAccessException e) {
                logger.error("Could not retrieve value for field...");
            }
        }
        // Return the JDBC type name
        return (String) map.get(Integer.valueOf(jdbcType));
    }
}

Related

  1. getJdbcType(int firebirdType)
  2. getJdbcType(String datatype)
  3. getJdbcType(String typeName)
  4. getJdbcTypeClass(int type)
  5. getJDBCTypeForNamedType(String aTypeName)
  6. getJDBCTypeName(int value)
  7. getJdbcTypeNames()
  8. getJDBCTypes()
  9. getLength(String format, String columnTypeName)