Marcio Coelho · Oct 29, 2019


Hi all....

I couldn't find documentation on how to create a blob using the cache JDBC driver.
I found only one reading example:

The createBlob Method of the connection class was not implemented:

Does anyone know how to create a blob without compromising the java heap space?


0 266
Discussion (7)2
Log in or sign up to continue


It probably should be createBlob.

I am so sorry about the syntax error. I Edited my post

Hello Kevin...

The problem is a byte[] and java heap space. I have 200Mb into a InputStream and convert this a byte[], cause java.lang.OutOfMemoryError: Java heap space

It's a piece of my code.... 


ByteArrayOutputStream buffer = new ByteArrayOutputStream();

int nRead;

byte[] data = new byte[1024];

while ((nRead =, 0, data.length)) != -1) {

    buffer.write(data, 0, nRead);


SerialBlob blob = new SerialBlob(buffer.toByteArray());

Hello Marcio,

The answer you are looking for can be found in the SerialBlob javadocs: this is the only known provided implementation of the java.sql.Blob interface. In particular, you would like the the SerialBlob(byte[]b) constructor to create a blob in Java.

Can I get more context about what you are trying to do? Are you trying to insert a stream to the datasource or retrieve a stream from the datasource or just make a blob in general?

Hello Kevin. Thank you for your attention.

I am trying to send an InputStream to the database.
My Stream is coming from a rest service (jax-rs, upload) I have an average file size of 200Mb.

I have a "prepareStatement" with sql query "Insert into <Class with %GlobalBinaryString property>" 

If you have a java.sql.PreparedStatement and what seems to be a subclass (since you can call read() on it), why not utilize java.sql.PreparedStatement.setBinaryStream(int parameterIndex, InputStream x)? I am not sure which version of com.intersys.jdbc.CacheDriver you are using, but it is likely that your driver version has that API supported.

try (
    java.sql.Connection        cnxn  = DriverMasnager.getConnection(url, cnxnProps);
    java.sql.PreparedStatement pstmt = cnxn.prepareStatement(
            "INSERT INTO tableWithBlobField VALUES(?)");
    pstmt.setBinaryStream(1, binaryStreamFromRestAPI);