java Clob类型 转String

1、我的数据库是oracle11g 遇到取出来的字段是clob类型,但是所需要的是string类型,写一个转换函数就可以解决问题了。

// Clob类型 转String
    public String ClobToString(Clob clob) throws SQLException, IOException {
      String reString = "";
      Reader is = clob.getCharacterStream();
      BufferedReader br = new BufferedReader(is);
      String s = br.readLine();
      StringBuffer sb = new StringBuffer();
      while (s != null) {
          sb.append(s);
          s = br.readLine();
      }
      reString = sb.toString();
      if(br!=null){
          br.close();
      }
      if(is!=null){
          is.close();
      }
      return reString;
     }

2、调用即可

pubKeyStr = ClobToString((Clob)app.get("pubkey"));
            priKeyStr = ClobToString((Clob)app.get("prikey"));

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0