Java examples for JDBC:JDBC Types
Getting the Name of a JDBC Type
import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; public class Main { static Map map; public static String getJdbcTypeName(int jdbcType) { if (map == null) { 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 {//from ww w. ja va2 s. c o m // Get field name String name = fields[i].getName(); // Get field value Integer value = (Integer) fields[i].get(null); // Add to map map.put(value, name); } catch (IllegalAccessException e) { } } } // Return the JDBC type name return (String) map.get(new Integer(jdbcType)); } }