Support Article
How to access CLOB data
Summary
How to retrieve the Character Large Object (CLOB) value from database using the connect-SQL?
Resolution
Perform the following local-change:
Use the following code. It uses the Java code invoked from an activity to retrieve the CLOB data and gets through the 4-K limitation. The database ( Data-Admin-DB-Name ) is configured to connect using a JDBC URL.
try
{
HashStringMap keysMap = new HashStringMap();
keysMap.put("pyRWDatabase","PMLandingTable");
keysMap.put("pxObjClass","Data-Admin-DB-Name");
ClipboardPage dbPage = tools.getDatabase().open(keysMap,false);
java.sql.Connection Conn = java.sql.DriverManager.getConnection(dbPage.getString("pyDatabaseURL"),dbPage.getString("pyDBUser"),dbPage.getString("pyDBPassword"));
java.sql.PreparedStatement cs= Conn.prepareStatement("select RECORD_UID, CUST_INC_STMNT from SERVICE_RECORD_LANDING_FINAL where RECORD_UID = 1038");
java.sql.ResultSet result = cs.executeQuery();
if (result.next()) {
String id = result.getString(1); // the uid
java.sql.Clob clb = result.getClob(2); // the blob
int clobLength = (int) clb.length();
StringBuilder sb = new StringBuilder();
java.io.Reader reader = clb.getCharacterStream();
java.io.BufferedReader br = new java.io.BufferedReader(reader);
String clobData;
while(null != (clobData = br.readLine())) {
sb.append(clobData);
}
String prntString = sb.toString();
br.close();
clb.free();
}
else
{
oLog.error("No Id found ");
}
//Cleanup DB resourses
result.close();
cs.close();
Conn.close();
} catch (Exception e){
oLog.error("Exception encountered" + e);
e.printStackTrace();
}
Published November 28, 2016 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.