blob类型

1.BLOB  
BLOB全称为二进制大型对象(Binary   Large   Object)。它用于存储数据库中的大型二进制对象。可存储的最大大小为4G字节  
2.CLOB  
CLOB全称为字符大型对象(Character   Large   Object)。它与LONG数据类型类似,只不过CLOB用于存储数据库中的大型单字节字符数据块,不支持宽度不等的字符集。可存储的最大大小为4G字节

     通常像图片、文件、音乐等信息就用BLOB字段来存储,先将文件转为二进制再存储进去。而像文章或者是较长的文字,就用CLOB存储,这样对以后的查询更新存储等操作都提供很大的方便。


/**
     * <把字符串转换成字节数组然后在封装成字符串>
     * <功能详细描述>
     * @param chinese
     * @return
     * @see [类、类#方法、类#成员]
     */ 
    public static String chineseToString(String chinese) 
    { 
        if (Global.isEmpty(chinese)) 
        { 
            return ""; 
        } 
        else 
        { 
            // 定义StringBuffer 
            StringBuffer sb = new StringBuffer(); 
             
            // 把传进来的字符串转换成字节数组 
            byte[] b = chinese.getBytes(); 
             
            byte[] temp = null; 
             
            // 遍历字节数组,把字节数组转换成字符串 
            for (int i = 0; i < b.length; i++) 
            { 
                temp = new byte[4]; 
                temp[0] = b[i]; 
                temp[1] = 0; 
                temp[2] = 0; 
                temp[3] = 0; 
                sb.append(lBytesToInt(temp)); 
                if (i < b.length - 1) 
                { 
                    sb.append("@"); 
                } 
            } 
             
            return sb.toString(); 
        } 
    } 
     
    /**
     * <把字节数组封装成的字符串转换成原来的字符串>
     * <功能详细描述>
     * @param stc
     * @return
     * @see [类、类#方法、类#成员]
     */ 
    public static String stringToChinese(String stc) 
    { 
        // 如果传递的字符串为空则直接返回空 
        if (Global.isEmpty(stc)) 
        { 
            return ""; 
        } 
        else 
        { 
            // 分割字符串 
            String[] s = stc.split("@"); 
            if (s.length > 0) 
            { 
                // 循环构造BYTE数组 
                byte[] b = new byte[s.length]; 
                for (int i = 0; i < s.length; i++) 
                { 
                    b[i] = (byte)Integer.parseInt(s[i]); 
                } 
                 
                // 根据BYTE数组构造字符串 
                return new String(b); 
            } 
            else 
            { 
                return ""; 
            } 
        } 
    } 
     
    /**
     * 将低字节数组转换为int
     * @param b byte[]
     * @return int
     */ 
    public static int lBytesToInt(byte[] b) 
    { 
        int s = 0; 
        for (int i = 0; i < 3; i++) 
        { 
            if (b[3 - i] >= 0) 
            { 
                s = s + b[3 - i]; 
            } 
            else 
            { 
                s = s + 256 + b[3 - i]; 
            } 
            s = s * 256; 
        } 
        if (b[0] >= 0) 
        { 
            s = s + b[0]; 
        } 
        else 
        { 
            s = s + 256 + b[0]; 
        } 
        return s; 
    } 

猜你喜欢

转载自952605615.iteye.com/blog/2390135