Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
In Talend tDBInput component, CLOB data types can not be handled properly when you are attempting to ingest data from source DB2 to Target one.
This article briefly introduces how to properly handle CLOB data types when ingesting from DB2 to Target using Talend.
The code below is a scratch version that needs testing and rewriting.
Use this as an example to study:
==Example code: === package routines; import java.sql.Clob;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.IOUtils; package routines; import java.sql.Clob;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.IOUtils; import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.lang.String; public class ClobUtils { public static String getClobAsString(Object obj) {
String out = null;
if (obj != null && obj instanceof Clob) {
out=getClobAsString((Clob) obj);
} else {
Logger.getLogger("ClobUtils").log(Level.FINE, "null value");
}
return out;
} public static String getClobAsString(Clob clobObject) {
String clobAsString = null;
if (clobObject != null) {
long clobLength;
try {
clobLength = clobObject.length(); if (clobLength <= Integer.MAX_VALUE) {
clobAsString = clobObject.getSubString(1, (int) clobLength);
} else {
InputStream in = clobObject.getAsciiStream();
StringWriter w = new StringWriter();
IOUtils.copy(in, w, "UTF-8");
clobAsString = w.toString();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return clobAsString;
}
}