I am trying to insert an input stream using camel SQL component (http://camel.apache.org/sql-component.html).
I have the following table in Oracle Database:
table EMPLOYEE(NAME varchar(32) ,SURNAME varchar(32) , PIC BLOB );
and the following route:
<route>
<from uri="direct:startOracle" />
<to uri="sql:INSERT INTO EMPLOYEE (Name, surname, pics) VALUES (# , # , #)?dataSource=#oracle" />
</route>
when I try to run the following code:
Resource r = contex.getResource("classpath:file/ciao.jpg");
InputStream inputStream = r.getInputStream();
aProducerTemplate.sendBody(new Object[] {"mario", "ross", inputStream});
I always get a kind incompatible third param (input stream).
The same code runs without error on MySQL database, but on Oracle does not work well .
I saw that component camel SQL use the following code as a strategy for the using of prepared statement:
// use argument setter as it deals with various JDBC drivers setObject vs setLong/setInteger/setString etc.
ArgumentPreparedStatementSetter setter = new ArgumentPreparedStatementSetter(args);
setter.setValues(ps);
but this strategy doesn't seem to use prepare statement as the following:
ps.setBinaryStream(3,inputStream,length);
but instead call the following code
ps.setObject(paramIndex, inputStream);
and it seem doesn't work very well on oracle db.
So the question is: will I change the Default SQL prepared statement strategy being used by SQL camel component? Or are there other ways?
Thank so much for the comment.
I have just found a solution:
Resource r = contex.getResource("classpath:file/ciao.jpg");
InputStream inputStream = r.getInputStream();
SqlLobValue blobVal = new SqlLobValue(inputStream, (int) r.getFile().length() );
SqlParameterValue blob = new SqlParameterValue(Types.BLOB,"BLOB", blobVal );
aProducerTemplate.sendBody(new Object[] {"Mario", "Rossi",blob} );
来源:https://stackoverflow.com/questions/34530594/how-to-insert-blob-using-camel-sql-component-with-oracle-database