Inserting a blob to Oracle DB

143 views
Skip to first unread message

p.balm...@googlemail.com

unread,
Aug 31, 2018, 9:02:31 AM8/31/18
to jDBI
I'm trying to insert a blob to an Oracle database and JDBIv3.

jdbi.useHandle(handle -> {

Connection connection = handle.getConnection();
Blob fileContents = connection.createBlob();
fileContents.setBytes(1, Files.readAllBytes(path));

handle.createUpdate("insert into <tableName> (id, input_data) select a_seq.nextval, :fileContents from dual")
.define("tableName", tableName)
.bind("fileContents", fileContents)
.execute();
});

I need to get the connection to create the Blob which is then  bound to the connection on which it was created. 
Is there a way to use SQLObjects with blobs.

I did try passing a by byte[] instead of a blob  but this gave me the following:

org.jdbi.v3.core.statement.UnableToExecuteStatementException: java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column





Steven Schlansker

unread,
Sep 1, 2018, 12:37:20 AM9/1/18
to jd...@googlegroups.com
I don't have much familiarity with Oracle blobs personally, but I would suggest writing an ArgumentFactory that produces an Argument for your byte[], and then on binding you can create the necessary Blob.  If that turns out to be useful generally, we could include it in the Oracle plugin.

--
You received this message because you are subscribed to the Google Groups "jDBI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jdbi+uns...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages