2

I have a QUERY column of type CLOB in database.

I am reading it in my program as:

SqlRowSet myRowSet = this.jdbcTemplate.queryForRowSet(this.sqlQuery);

while(myRowSet.next()){
   String currentClobString = myRowSet.getString("QUERY")
   System.out.println(currentClobString);
}

But this is giving the below output:

javax.sql.rowset.serial.SerialClob@7cfe7cfe

How can I correct this?

Thanks for reading!

Vicky
  • 16,679
  • 54
  • 139
  • 232

1 Answers1

4

You can call getObject(String columnLabel) method and use the IOutils from apache commons. This sample code is taken from another SO response.

    InputStream in = clobObject.getAsciiStream();
    StringWriter w = new StringWriter();
    IOUtils.copy(in, w);
    String clobAsString = w.toString();
Amit Parashar
  • 1,447
  • 12
  • 15
  • You mean after the following line: Object clobObject = myRowSet.getObject("QUERY") --- above code ???? – Vicky Apr 15 '15 at 16:40
  • Object queryClob = snapshotQueriesRowSet.getObject("QUERY"); InputStream in = queryClob.getAsciiStream(); error : getAsciiStream is undefined for type Object.. – Vicky Apr 15 '15 at 16:43
  • 1
    SerialClob implements Clob. You need type cast. Clob clobObject = (Clob)queryClob ; – Amit Parashar Apr 15 '15 at 16:52