string clob/blob 互转


String s1="1231dsdgasd的飒飒大";     

      Clob c = new SerialClob(s1.toCharArray());//String 转 clob
      Blob b = new SerialBlob(s1.getBytes("GBK"));//String 转 blob

//      也可以这样不传字符集名称,默认使用系统的
//      Blob b = new SerialBlob(s1.getBytes());      

      String clobString = c.getSubString(1, (int) c.length());//clob 转 String
      String blobString = new String(b.getBytes(1, (int) b.length()),"GBK");//blob 转 String

//      前面若没传入字符集名称,则这里也不需要传入,以免出错
//      String blobString = new String(b.getBytes(1, (int) b.length()));      

      System.out.println(clobString);
      System.out.println(blobString);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM