Package com.aceql.jdbc.commons
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
-
Method Summary
Modifier and Type Method Description voidfree()InputStreamgetAsciiStream()ReadergetCharacterStream()ReadergetCharacterStream(long pos, long length)StringgetSubString(long pos, int length)longlength()longposition(String searchstr, long start)This method is not yet implemented in the AceQL JDBC Driver.longposition(Clob searchstr, long start)This method is not yet implemented in the AceQL JDBC Driver.OutputStreamsetAsciiStream(long pos)WritersetCharacterStream(long pos)intsetString(long pos, String str)intsetString(long pos, String str, int offset, int len)This method is not yet implemented in the AceQL JDBC Driver.voidtruncate(long len)This method is not yet implemented in the AceQL JDBC Driver.
-
Method Details
-
length
- Specified by:
lengthin interfaceClob- Throws:
SQLException
-
getSubString
- Specified by:
getSubStringin interfaceClob- Throws:
SQLException
-
getCharacterStream
- Specified by:
getCharacterStreamin interfaceClob- Throws:
SQLException
-
getCharacterStream
- Specified by:
getCharacterStreamin interfaceClob- Throws:
SQLException
-
getAsciiStream
- Specified by:
getAsciiStreamin interfaceClob- Throws:
SQLException
-
position
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
positionin interfaceClob- Throws:
SQLException
-
position
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
positionin interfaceClob- Throws:
SQLException
-
setString
- Specified by:
setStringin interfaceClob- Throws:
SQLException
-
setString
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
setStringin interfaceClob- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStreamin interfaceClob- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStreamin interfaceClob- Throws:
SQLException
-
truncate
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
truncatein interfaceClob- Throws:
SQLException
-
free
- Specified by:
freein interfaceClob- Throws:
SQLException
-