Jason B Herald

Feed Rss

Oracle Blob (JDBC) – How to

05.27.2008, Java, by .

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