CLOB/BLOB互转

1. [代码]CLOB/BLOB互转     跳至 [1] [2] [全屏预览] 
view sourceprint?01         String s1="1231dsdgasd的飒飒大";  

02            

03         Clob c = new SerialClob(s1.toCharArray());//String 转 clob  

04         Blob b = new SerialBlob(s1.getBytes("GBK"));//String 转 blob  

05 //      也可以这样不传字符集名称,默认使用系统的  

06 //      Blob b = new SerialBlob(s1.getBytes());  

07            

08         String clobString = c.getSubString(1, (int) c.length());//clob 转 String  

09         String blobString = new String(b.getBytes(1, (int) b.length()),"GBK");//blob 转 String  

10 //      前面若没传入字符集名称,则这里也不需要传入,以免出错  

11 //      String blobString = new String(b.getBytes(1, (int) b.length()));  

12            

13         System.out.println(clobString);  

14         System.out.println(blobString); 

2. [代码][Java]代码     跳至 [1] [2] [全屏预览] 
view sourceprint?1 1231dsdgasd的飒飒大  

2 1231dsdgasd的飒飒大 

 

你可能感兴趣的:(clob)