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 void
free()
InputStream
getAsciiStream()
Reader
getCharacterStream()
Reader
getCharacterStream(long pos, long length)
String
getSubString(long pos, int length)
long
length()
long
position(String searchstr, long start)
This method is not yet implemented in the AceQL JDBC Driver.long
position(Clob searchstr, long start)
This method is not yet implemented in the AceQL JDBC Driver.OutputStream
setAsciiStream(long pos)
Writer
setCharacterStream(long pos)
int
setString(long pos, String str)
int
setString(long pos, String str, int offset, int len)
This method is not yet implemented in the AceQL JDBC Driver.void
truncate(long len)
This method is not yet implemented in the AceQL JDBC Driver.
-
Method Details
-
length
- Specified by:
length
in interfaceClob
- Throws:
SQLException
-
getSubString
- Specified by:
getSubString
in interfaceClob
- Throws:
SQLException
-
getCharacterStream
- Specified by:
getCharacterStream
in interfaceClob
- Throws:
SQLException
-
getCharacterStream
- Specified by:
getCharacterStream
in interfaceClob
- Throws:
SQLException
-
getAsciiStream
- Specified by:
getAsciiStream
in interfaceClob
- Throws:
SQLException
-
position
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
position
in interfaceClob
- Throws:
SQLException
-
position
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
position
in interfaceClob
- Throws:
SQLException
-
setString
- Specified by:
setString
in interfaceClob
- Throws:
SQLException
-
setString
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
setString
in interfaceClob
- Throws:
SQLException
-
setAsciiStream
- Specified by:
setAsciiStream
in interfaceClob
- Throws:
SQLException
-
setCharacterStream
- Specified by:
setCharacterStream
in interfaceClob
- Throws:
SQLException
-
truncate
This method is not yet implemented in the AceQL JDBC Driver.- Specified by:
truncate
in interfaceClob
- Throws:
SQLException
-
free
- Specified by:
free
in interfaceClob
- Throws:
SQLException
-