如何使用camel SQL组件和Oracle数据库插入blob [英] How to insert blob using camel SQL component with Oracle Database
问题描述
我尝试使用camel SQL组件插入输入流( http://camel.apache) .org / sql-component.html )。
I am trying to insert an input stream using camel SQL component (http://camel.apache.org/sql-component.html).
我在Oracle数据库中有下表:
I have the following table in Oracle Database:
table EMPLOYEE(NAME varchar(32) ,SURNAME varchar(32) , PIC BLOB );
和以下路线:
<route>
<from uri="direct:startOracle" />
<to uri="sql:INSERT INTO EMPLOYEE (Name, surname, pics) VALUES (# , # , #)?dataSource=#oracle" />
</route>
:
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).
相同的代码在MySQL数据库上运行时没有错误,但是在Oracle上无法正常工作。
The same code runs without error on MySQL database, but on Oracle does not work well .
我看到组件camel SQL使用以下代码作为使用预编译语句的策略:
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);
,但此策略似乎不使用prepare语句如下:
but this strategy doesn't seem to use prepare statement as the following:
ps.setBinaryStream(3,inputStream,length);
,而是调用以下代码:
ps.setObject(paramIndex, inputStream);
似乎在oracle db上效果不好。
and it seem doesn't work very well on oracle db.
所以问题是:我会更改SQL camel组件使用的默认SQL准备语句策略吗?还是有其他方法?
So the question is: will I change the Default SQL prepared statement strategy being used by SQL camel component? Or are there other ways?
推荐答案
非常感谢评论。
我刚刚找到了一个解决方案:
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} );
这篇关于如何使用camel SQL组件和Oracle数据库插入blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!