This is an automated email from the ASF dual-hosted git repository.
dspavlov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 8e9d1d4be2b IGNITE-23380 Add JDBC thin BLOB and CLOB docs (#13259)
8e9d1d4be2b is described below
commit 8e9d1d4be2b9ef92367dfde7cf4fb6a8664b146f
Author: ignitetcbot <[email protected]>
AuthorDate: Wed Jul 15 15:57:07 2026 +0300
IGNITE-23380 Add JDBC thin BLOB and CLOB docs (#13259)
Codex co-authored-by: Dmitriy Pavlov <[email protected]>
---
docs/_docs/SQL/JDBC/jdbc-driver.adoc | 24 +++++++
.../org/apache/ignite/snippets/JDBCThinDriver.java | 73 +++++++++++++++++++---
2 files changed, 89 insertions(+), 8 deletions(-)
diff --git a/docs/_docs/SQL/JDBC/jdbc-driver.adoc
b/docs/_docs/SQL/JDBC/jdbc-driver.adoc
index ffd36a8ddde..b07fb840110 100644
--- a/docs/_docs/SQL/JDBC/jdbc-driver.adoc
+++ b/docs/_docs/SQL/JDBC/jdbc-driver.adoc
@@ -231,6 +231,30 @@ while (rs.next()) {
}
----
+=== BLOB and CLOB Values
+
+The JDBC Thin driver supports standard `java.sql.Blob` and `java.sql.Clob`
objects for binary and character values.
+Store BLOB data in SQL `BINARY` columns and CLOB data in SQL `VARCHAR` columns.
+
+[NOTE]
+====
+BLOB and CLOB support in the JDBC Thin driver is available since Apache Ignite
2.17.
+CLOB values are intentionally stored in SQL `VARCHAR` columns, and BLOB values
are stored in SQL `BINARY` columns.
+====
+
+You can create values with `Connection.createBlob()` and
`Connection.createClob()`, bind them with `PreparedStatement.setBlob()` and
`PreparedStatement.setClob()`, and read them with `ResultSet.getBlob()` and
`ResultSet.getClob()`.
+
+[source,java]
+----
+include::{javaFile}[tags=blob-clob, indent=0]
+----
+
+BLOB values also support binary stream APIs, including
`PreparedStatement.setBlob(int, InputStream)`, `PreparedStatement.setBlob(int,
InputStream, long)`, `PreparedStatement.setBinaryStream()`,
`ResultSet.getBinaryStream()`, and `Blob.getBinaryStream()`.
+When a stream length is provided, it must be non-negative and must match the
actual number of bytes read from the stream.
+
+CLOB values are supported through `Clob` object methods such as `setString()`,
`getSubString()`, and `getCharacterStream()`.
+Reader-based CLOB setter APIs, such as `PreparedStatement.setClob(int,
Reader)`, and direct `ResultSet.getCharacterStream()` calls are not supported.
+
=== Partition Awareness [[partition-awareness]]
Partition awareness is a feature that makes the JDBC driver "aware" of the
partition distribution in the cluster.
diff --git
a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JDBCThinDriver.java
b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JDBCThinDriver.java
index 6ab942b7f2b..48824467be1 100644
---
a/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JDBCThinDriver.java
+++
b/docs/_docs/code-snippets/java/src/main/java/org/apache/ignite/snippets/JDBCThinDriver.java
@@ -16,13 +16,20 @@
*/
package org.apache.ignite.snippets;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.sql.Blob;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteJdbcThinDataSource;
+import org.apache.ignite.Ignition;
public class JDBCThinDriver {
@@ -132,6 +139,61 @@ public class JDBCThinDriver {
conn.close();
}
+ void blobAndClob() throws ClassNotFoundException, SQLException {
+
+ Connection conn = getConnection();
+ // tag::blob-clob[]
+ // CLOB values are stored in VARCHAR columns, and BLOB values are
stored in BINARY columns.
+ conn.createStatement().executeUpdate(
+ "CREATE TABLE IF NOT EXISTS DocumentStore (id INT PRIMARY KEY,
payload BINARY, body VARCHAR)");
+
+ byte[] payload = "binary payload".getBytes(StandardCharsets.UTF_8);
+
+ PreparedStatement insert = conn.prepareStatement(
+ "INSERT INTO DocumentStore(id, payload, body) VALUES (?, ?,
?)");
+
+ Blob blob = conn.createBlob();
+ blob.setBytes(1, payload);
+
+ Clob clob = conn.createClob();
+ clob.setString(1, "large text body");
+
+ insert.setInt(1, 1);
+ insert.setBlob(2, blob);
+ insert.setClob(3, clob);
+ insert.executeUpdate();
+
+ PreparedStatement streamInsert = conn.prepareStatement(
+ "INSERT INTO DocumentStore(id, payload, body) VALUES (?, ?,
?)");
+
+ streamInsert.setInt(1, 2);
+ streamInsert.setBlob(2, new ByteArrayInputStream(payload),
payload.length);
+ streamInsert.setString(3, "large text body");
+ streamInsert.executeUpdate();
+
+ PreparedStatement select = conn.prepareStatement("SELECT payload, body
FROM DocumentStore WHERE id = ?");
+
+ select.setInt(1, 1);
+
+ ResultSet rs = select.executeQuery();
+
+ if (rs.next()) {
+ Blob selectedBlob = rs.getBlob("payload");
+ byte[] selectedPayload = selectedBlob.getBytes(1,
(int)selectedBlob.length());
+
+ Clob selectedClob = rs.getClob("body");
+ String selectedBody = selectedClob.getSubString(1,
(int)selectedClob.length());
+
+ InputStream selectedPayloadStream = rs.getBinaryStream("payload");
+
+ assert selectedPayload.length == payload.length;
+ assert selectedBody.equals("large text body");
+ assert selectedPayloadStream != null;
+ }
+ // end::blob-clob[]
+ conn.close();
+ }
+
void handleException() throws ClassNotFoundException, SQLException {
Connection conn = getConnection();
@@ -217,21 +279,16 @@ public class JDBCThinDriver {
}
public static void main(String[] args) throws Exception {
- // Ignite ignite = Util.startNode();
+ Ignite ignite = Ignition.start();
try {
JDBCThinDriver j = new JDBCThinDriver();
- // j.getConnection();
- // j.multipleEndpoints();
- // j.connectionFromDatasource();
- // j.partitionAwareness();
-
- j.ssl();
+ j.blobAndClob();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
} finally {
- // ignite.close();
+ ignite.close();
}
}
}