ClobColumnTranslator implements ColumnWriter, ColumnTranslator { @Override public String translate(JdbcResultRow rs, int column) throws SQLException, IOException { return toString((Clob) rs.getFieldValue(column)); } ClobColumnTranslator(); @Override String translate(JdbcResultRow rs, int column); @Override String translate(JdbcResultRow rs, String columnName); @Override void write(JdbcResultRow rs, int column, OutputStream out); @Override void write(JdbcResultRow rs, String columnName, OutputStream out);  }
@Test public void testClobToString() throws Exception { Clob clob = new SerialClob("SomeData".toCharArray()); JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", clob, Types.CLOB); String translated = translator.translate(row, 0); assertEquals("SomeData", translated); }
@Test public void testClobToStringColumnName() throws Exception { Clob clob = new SerialClob("SomeData".toCharArray()); JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", clob, Types.CLOB); String translated = translator.translate(row, "testField"); assertEquals("SomeData", translated); }
@Test public void testClobIncorrectType() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", new Integer(999), Types.CLOB); try { translator.translate(row, 0); fail(); } catch (Exception ex) { } }
@Test public void testClobIncorrectTypeColumnName() throws Exception { JdbcResultRow row = new JdbcResultRow(); row.setFieldValue("testField", new Integer(999), Types.CLOB); try { translator.translate(row, "testField"); fail(); } catch (Exception ex) { } }