Oracle Blob (JDBC) - How to

May 27th, 2008

This morning I needed to insert a file’s contents into a blob on an oracle database so here is the method used to do that (look for a future post on dropping a file into an applet).

/* File Loaded here into a File Object as f */
PreparedStatement ps = conn.prepareStatement(”INSERT INTO TBL VALUES(?, ?)”);
ps.setString(1, f.getName());
FileInputStream fis = new FileInputStream(f);
ps.setBinaryStream(2, fis, fis.available());
ps.execute();
ps.close();

And tada your record will be loaded into the blob.

*** Not Shown ***
Oracle JDBC Connection - This example does not use any framework/connection helper (i.e. Hibernate/EJB)

Leave a Reply

You must be logged in to post a comment.