1

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?

metropolision
  • 405
  • 4
  • 10
arius81
  • 21
  • 5
  • Its more a question to spring jdbc if they can support using setBinaryStream if the parameter value is InputStream based etc. – Claus Ibsen Jan 01 '16 at 23:07
  • 1
    You can try wrap that input stream in a SqlParameterValue class and specify the type as a CLOB, then spring ought to use that information. – Claus Ibsen Jan 01 '16 at 23:13

1 Answers1

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} );
arius81
  • 21
  • 5