e291. getting the name of a jdbc type.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 31 行

TXT
31
字号
This example implements a convenient method for converting a java.sql.Types integer value into a printable name. This method is useful for debugging. The method uses reflection to get all the field names from java.sql.Types. It then retrieves their values and creates a map of values to names. 
    // This method returns the name of a JDBC type.
    // Returns null if jdbcType is not recognized.
    public static String getJdbcTypeName(int jdbcType) {
        // Use reflection to populate a map of int values to names
        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 {
                    // 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));
    }
    static Map map;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?