oracle处理生僻字

生僻字㛃在ZHS16GBK字符集下默认无法正常显示,项目已经做过一段时间,oracle字符集不能修改的情况下,选择了把生僻字转码为16进制存,然后解码的读取。直接贴代码。

package mytest;

public class Test6 {
	public static String str2HexStr(String str) {
	    char[] chars = "0123456789ABCDEF".toCharArray();
	    StringBuilder sb = new StringBuilder("");
	    byte[] bs = str.getBytes();
	    int bit;
	    for (int i = 0; i < bs.length; i++) {
	        bit = (bs[i] & 0x0f0) >> 4;
	        sb.append(chars[bit]);
	        bit = bs[i] & 0x0f;
	        sb.append(chars[bit]);
	    }
	    return sb.toString().trim();
	}
	
	public static String hexStr2Str(String hexStr) {
	    String str = "0123456789ABCDEF";
	    char[] hexs = hexStr.toCharArray();
	    byte[] bytes = new byte[hexStr.length() / 2];
	    int n;
	    for (int i = 0; i < bytes.length; i++) {
	        n = str.indexOf(hexs[2 * i]) * 16;
	        n += str.indexOf(hexs[2 * i + 1]);
	        bytes[i] = (byte) (n & 0xff);
	    }
	    return new String(bytes);
	}
	public static void main(String[] args) {
		String str = "nihao123㛃";
		str = str2HexStr(str);
//		save(str); read(str);
		System.out.println(str);
		str = hexStr2Str(str);
		System.out.println(str);
	}
}

你可能感兴趣的:(oracle)