java blob类型和字符串转换

本秂侑毒 提交于 2019-12-27 12:02:53

 String str="123456";
    //String 转 clob
    Clob clob = new SerialClob(str.toCharArray());
  //String 转 blob
    Blob blob = new SerialBlob(str.getBytes("GBK"));
     
    //也可以这样不传字符集名称,默认使用系统的
    //Blob blob = new SerialBlob(str.getBytes());
    String clobToString = clob.getSubString(1, (int) clob.length());//clob 转 String
  //blob 转 String
    String blobToString = new String(blob.getBytes(1, (int) blob.length()),"GBK");
     
    //前面若没传入字符集名称,则这里也不需要传入,以免出错
    //String blobString = new String(blob.getBytes(1, (int) blob.length()));
     
    System.out.println(clobToString);
    System.out.println(blobToString);

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!