java - How to use a Blob object as parameter for MapSqlParameterSource in Oracle -


there table mentionned below :

create table table (    id_demand             number not null ,    file_blob blob ) ;  id_demand   file_blob --------------------- 12          (null)       

i'm trying update "blob" field in oracle db using procedure :

create or replace function update_blob(   p_id_demand in table.id_demand%type,   p_file_blob in table.file_blob%type )return number  begin    update table   set file_blob = p_file_blob   id_demand = p_id_demand;     return 1;   exception     when others      return 0;  end update_blob; 

first, i'm reading file :

int iddemand = 12; file file = new file("c:\\file.xls"); fileinputstream fileinput = new fileinputstream(file); byte[] bytes = ioutils.tobytearray(fileinput); 

and, next, prepare parameters :

blob blob = new serialblob(bytes); final map<string, object> params = new hashmap<string, object>(); params.put("p_id_demand", iddemand);         params.put("p_file_blob", blob); 

after executing procedure simplejdbctemplate (from spring) :

final bigdecimal li = callfunction("update_blob",bigdecimal.class, params, source.base); 

definition of callfunction :

public static bigdecimal callfunction(string functionname,map <string, object> parameters, source datasource) throws exception{ compteur compteur = new compteur(); compteur.start(); final simplejdbccall simplejdbctemplate = new simplejdbccall(datasourcehelper.getdatasource(datasource)); configuretemplateforfunction(functionname, simplejdbctemplate); final mapsqlparametersource in = new mapsqlparametersource().addvalues(parameters);  if (log.isinfoenabled()) {     infofunction(functionname, parameters); }    futuretask<bigdecimal> future =     new futuretask<bigdecimal>(new callable<bigdecimal>() {     public bigdecimal call() {         return simplejdbctemplate.executefunction(bigdecimal.class,in);     }}); executor.execute(future);  bigdecimal out = future.get(timeout_max_in_secondes, timeunit.seconds); compteur.stop();  if (log.isinfoenabled()){     log.info("execute : " + functionname + " -- duration --> " + compteur.gettime()); } return out; } 

i'm getting error unknown column type blob parameter. tried edit procedure , code use integer parameter , worked.

edit : used callablestatement because apparently there no other way of doing want wanted.


Comments

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
    It is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
    or learn thru Java Online Training from India Students.

    ReplyDelete

Post a Comment