JDBCUtils { public static String clobToString(Clob value) { String result = ""; try (Reader valueReader = value.getCharacterStream()) { result = IOUtils.toString(valueReader); } catch (Exception e) { log.debug("Not able to convert Clob", e); } return result; }  static List<SQLDataSourceDef> listDatasourceDefs(); static void execute(Connection connection, String sql); static T metadata(Connection connection, String sql, Function<ResultSetMetaData, T> callback); static ResultSetHandler executeQuery(Connection connection, String sql); static Dialect dialect(Connection connection); static Dialect dialect(String url, int majorVersion); static Dialect dialect(String dbName); static List<Column> getColumns(ResultSet resultSet, String[] exclude); static String fixCase(Connection connection, String id); static List<String> getWordsBetweenQuotes(String s); static String changeCaseExcludeQuotes(String s, boolean upper); static ColumnType calculateType(int sqlDataType); static String clobToString(Clob value); static final Dialect DEFAULT; static final Dialect H2; static final Dialect MYSQL; static final Dialect POSTGRES; static final Dialect ORACLE; static final Dialect ORACLE_LEGACY; static final Dialect SQLSERVER; static final Dialect DB2; static final Dialect SYBASE_ASE; static final Dialect MONETDB; static final String[] QUOTES; }
@Test public void clobToStringTest() throws SQLException { String TEST = "TEST"; StringReader testReader = new StringReader(TEST); when(clob.getCharacterStream()).thenReturn(testReader); assertEquals(TEST, JDBCUtils.clobToString(clob)); assertTrue(JDBCUtils.clobToString(null).isEmpty()); when(clob.getCharacterStream()).thenThrow(new RuntimeException()); assertTrue(JDBCUtils.clobToString(clob).isEmpty()); }