Most efficient solution for reading CLOB to String, and String to CLOB in Java?

前端 未结 11 1256
长发绾君心
长发绾君心 2020-12-01 07:04

I have a big CLOB (more than 32kB) that I want to read to a String, using StringBuilder. How do I do this in the most efficient way? I can not use the \"int length\" constru

11条回答
  •  渐次进展
    2020-12-01 08:07

    Ok I will suppose a general use, first you have to download apache commons, there you will find an utility class named IOUtils which has a method named copy();

    Now the solution is: get the input stream of your CLOB object using getAsciiStream() and pass it to the copy() method.

    InputStream in = clobObject.getAsciiStream();
    StringWriter w = new StringWriter();
    IOUtils.copy(in, w);
    String clobAsString = w.toString();
    

提交回复
热议问题