Class AceQLClob

java.lang.Object
com.aceql.jdbc.commons.AceQLClob
All Implemented Interfaces:
Clob

public class AceQLClob
extends Object
implements Clob
Clob implementation. Allows to use Clob objects for Clobs uploading (INSERT/UPDATE) and downloading (SELECT).

INSERT example:
 File file = new File("/my/file/path");

 String sql = "insert into documentation values (?, ?)";
 PreparedStatement preparedStatement = connection.prepareStatement(sql);

 int i = 1;
 preparedStatement.setInt(i++, itemId);

 // Create the Clob instance using the current Connection:
 Clob clob = connection.createClob();

 // Syntax using a String:
 clob = connection.createClob();
 String str = FileUtils.readFileToString(file, "UTF-8");
 clob.setString(1, str);
 preparedStatement.setClob(i++, clob);

 // Syntax using a stream:
 clob = connection.createClob();
 Writer out = clob.setCharacterStream(1);
 IOUtils.copy(new FileInputStream(file), out, "UTF-8");
 preparedStatement.setClob(i++, clob);

 preparedStatement.executeUpdate();
 preparedStatement.close();
 
SELECT example using a String
 String sql = "select * from documentation where item_id = ?";
 PreparedStatement preparedStatement = connection.prepareStatement(sql);
 preparedStatement.setInt(1, 1);

 ResultSet rs = preparedStatement.executeQuery();

 if (rs.next()) {
     Clob clob = rs.getClob(2);

     // Community Edition: Get the Clob string in memory and store them into a file
     String str = clob.getSubString(1, 0);

     File file = new File("/my/file/path");
     FileUtils.write(file, str, "UTF-8");
 }
 preparedStatement.close();
 rs.close();
 
SELECT example using a File:
 String sql = "select * from documentation where item_id = ?";
 PreparedStatement preparedStatement = connection.prepareStatement(sql);
 preparedStatement.setInt(1, 1);

 ResultSet rs = preparedStatement.executeQuery();

 if (rs.next()) {
     Clob clob = rs.getClob(2);

     File file = new File("/my/file/path");
     // Get the Reader stream from the Clob and copy into a file
     try (Reader reader = clob.getCharacterStream()) {
        IOUtils.copy(reader, new FileOutputStream(file), "UTF-8");
     }
 }

 preparedStatement.close();
 rs.close();
 
Note that Clobs can be updated or read without using a Clob instance.

INSERT/UPDATE can be done using:
SELECT can be done using:
Since:
8.0
Author:
Nicolas de Pomereu