Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

How to access CLOB data

SA-4732

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

Was this useful?

100% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice
Contact us