Retrieve data from a smart large object

The example in this topic illustrates the steps in Accessing smart large objects.

The following code example shows how to access the smart large object data using HCL OneDB™ extension classes:
byte[] buffer  = new byte[200];
System.out.println("Reading data now ...");
try
   {
   int row = 0;
   Statement stmt = myConn.createStatement();
   ResultSet rs =  stmt.executeQuery("Select * from demo_14");
   while( rs.next() )
      {
      row++;
      String str = rs.getString(1);
      InputStream value = rs.getAsciiStream(2);
      IfxBblob b = (IfxBblob) rs.getBlob(2);
      IfxLocator loPtr = b.getLocator();
      IfxSmartBlob smb = new IfxSmartBlob(myConn);
      int loFd = smb.IfxLoOpen(loPtr, smb.LO_RDONLY);

      System.out.println("The Smart Blob is Opened for reading ..");
      int number = smb.IfxLoRead(loFd, buffer, buffer.length);
      System.out.println("Read total " + number  + " bytes");
      smb.IfxLoClose(loFd);
      System.out.println("Closed the Smart Blob ..");
      smb.IfxLoRelease(loPtr);
      System.out.println("Locator is released ..");
      }
   rs.close();
   }
catch(SQLException e)
   {
   System.out.println("Select Failed ...\n" +e.getMessage());
         }

First, the ResultSet.getBlob() method gets an object of type BLOB. The casting is required to convert the returned object to an object of type IfxBblob. Next, the IfxBblob.getLocator() method gets an IfxLocator object from the IfxBblob object. After the IfxLocator object is available, you can instantiate an IfxSmartBlob object and use the IfxLoOpen() and IfxLoRead() methods to read the smart large object data. Fetching CLOB data is similar, but it uses the methods ResultSet.getClob(), IfxCblob.getLocator(), and so on.

If you use getBlob() or getClob() to fetch data from a column of type BLOB, you do not need to use the HCL OneDB extensions to retrieve the actual BLOB content as outlined in the preceding sample code. You can simply use Java.Blob.getBinaryStream() or Java.Clob.getAsciiStream() to retrieve the content. HCL OneDB JDBC Driver implicitly gets the content from the database server for you, using basically the same steps as the sample code. This approach is simpler than the approach of the preceding example but does not provide as many options for reading the contents of the BLOB column.