How to insert blob using camel SQL component with Oracle Database

你。 提交于 2019-12-06 14:00:15

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!