6 Replies Latest reply on Oct 7, 2009 9:43 AM by vu.tuan.anh

    Reading large large string from database

    Steve Bishop Level 2
      I am reading is a large string value. It's data type in Oracle is CLOB. I was originally casting it to vARCHAR2(4000) in the select statement, but just realized the data can be larger than 4000. I took out the cast and have tried changing to several data types, but they all error out. How can I read in string data greater than 4000 characters?
        • 1. Re: Reading large large string from database
          Steve Bishop Level 2
          I used JDBC in a script object.
          • 2. Re: Reading large large string from database
            HowardTreisman Level 1
            Use a String variable with unlimited length (there's a checkbox to control it when you define the string variable). In older versions, you can set the length to -1.
            Howard
            http://www.avoka.com
            • 3. Re: Reading large large string from database
              Steve Bishop Level 2
              It gave an error that it could not put a CLOB into a String.
              • 4. Re: Reading large large string from database
                HowardTreisman Level 1
                What's the exact error?
                • 5. Re: Reading large large string from database
                  You must use Java to do this, the Execute Script operation makes it simple. I have put together a little process to demonstrate, and I can paste the Java from the Execute Script step below.

                  It's all in the data-typing. In the sample I built, the BigString and NewBigString process variables are of LiveCycle type "string" with unlimited size. These become CLOBs in the database. When read as a CLOB object using JDBC, converted to Java Strings, they then can be loaded into the LiveCycle Process data and the API handles the rest.

                  Let me know if I'm not clear enough with my explanation.
                  Jeff A Yates
                  http://www.avoka.com
                  ------
                  import java.sql.Connection;
                  import java.sql.PreparedStatement;
                  import java.sql.Statement;
                  import java.sql.ResultSet;
                  import javax.sql.DataSource;
                  import javax.naming.InitialContext;

                  int processId = patExecContext.getProcessDataIntValue("/process_data/@id");

                  InitialContext context = new InitialContext();
                  Connection connection = ((DataSource)context.lookup("java:/IDP_DS")).getConnection();

                  String queryQuery = "select bigdocument, bigstring from tb_pt_workwithxlobs where process_instance_id = ?";
                  PreparedStatement queryStatement = connection.prepareStatement(queryQuery);

                  try {
                  queryStatement.setInt(1, processId);
                  ResultSet results = queryStatement.executeQuery();
                  results.next();

                  java.sql.Blob documentBlob = results.getBlob(1);
                  com.adobe.idp.Document document = new com.adobe.idp.Document(documentBlob.getBinaryStream());
                  patExecContext.setProcessDataValue("/process_data/@NewBigDocument", document);

                  java.sql.Clob stringClob = results.getClob(2);
                  patExecContext.setProcessDataValue("/process_data/@NewBigString", stringClob.getSubString(1L, (int)stringClob.length()));
                  } catch(Exception ex) {
                  ex.printStackTrace();
                  }

                  queryStatement.close();
                  connection.close();
                  • 6. Re: Reading large large string from database
                    vu.tuan.anh Level 1

                    Just happen to refer to this thread.

                     

                    You can use DBMS_LOB.SUBSTR to query repeatedly 4000 characters out of the field and concat them after finish.


                    E.g

                    SELECT
                    DBMS_LOB.SUBSTR(FieldName, 2000, ?)
                    FROM TableName

                     

                    ? is replace with a counter, increase by 2000 each time.

                     

                    Regards,

                    Tuan Anh