Spring SqlRowSet 使用 JdbcTemplate 将 Clob 获取为字符串
Spring SqlRowSet getting Clob as String using JdbcTemplate
我在数据库中有一个 QUERY
类型 CLOB
的列。
我正在我的程序中阅读它:
SqlRowSet myRowSet = this.jdbcTemplate.queryForRowSet(this.sqlQuery);
while(myRowSet.next()){
String currentClobString = myRowSet.getString("QUERY")
System.out.println(currentClobString);
}
但这给出了以下输出:
javax.sql.rowset.serial.SerialClob@7cfe7cfe
我该如何纠正?
感谢阅读!
您可以调用 getObject(String columnLabel) 方法并使用来自 apache commons 的 IOutils。此示例代码取自另一个 SO 响应。
InputStream in = clobObject.getAsciiStream();
StringWriter w = new StringWriter();
IOUtils.copy(in, w);
String clobAsString = w.toString();
我在数据库中有一个 QUERY
类型 CLOB
的列。
我正在我的程序中阅读它:
SqlRowSet myRowSet = this.jdbcTemplate.queryForRowSet(this.sqlQuery);
while(myRowSet.next()){
String currentClobString = myRowSet.getString("QUERY")
System.out.println(currentClobString);
}
但这给出了以下输出:
javax.sql.rowset.serial.SerialClob@7cfe7cfe
我该如何纠正?
感谢阅读!
您可以调用 getObject(String columnLabel) 方法并使用来自 apache commons 的 IOutils。此示例代码取自另一个 SO 响应。
InputStream in = clobObject.getAsciiStream();
StringWriter w = new StringWriter();
IOUtils.copy(in, w);
String clobAsString = w.toString();