⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e291. getting the name of a jdbc type.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -