Insert BLOB using java for both DB2 and Oracle -


i validating application developed on oracle db2. since don't want maintain 2 separate sources, need query insert blob field, works in both oracle , db2. don't have identifier distinguish under db application running.

i used utl_raw.cast_to_raw in oracle , cast() blob in db2 mutually incompatible.

you won't able find common sql uses kind of casting. can "plain" sql using jdbc's setbinarystream()

preparedstatement pstmt = connection.preparestatement(    "insert blob_table (id, blob_data) values (?, ?)";  file blobfile = new file("your_document.pdf"); inputstream in = new fileinputstream(blobfile);  pstmt.setint(1, 42); pstmt.setbinarystream(2, in, (int)blobfile.length()); pstmt.executeupdate(); connection.commit(); 

you can use setbinarystream() same way update statement.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -