如何在 Oracle 数据库中使用骆驼 SQL 组件插入 blob [英] How to insert blob using camel SQL component with Oracle Database

查看:56
本文介绍了如何在 Oracle 数据库中使用骆驼 SQL 组件插入 blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用骆驼 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>

当我尝试运行以下代码时:

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).

同样的代码在 MySQL 数据库上运行没有错误,但在 Oracle 上运行得不好.

The same code runs without error on MySQL database, but on Oracle does not work well .

我看到组件camel SQL使用以下代码作为使用prepared statement的策略:

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} );

这篇关于如何在 Oracle 数据库中使用骆驼 SQL 组件插入 blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆