RSS Feed for This PostCurrent Article

Java: Insert a BLOB Object Using iBATIS

Well, inserting a Oracle BLOB object using iBATIS is actually very straightforward. In your SQL mapping file you use the BLOB data type.

<!DOCTYPE sqlMap PUBLIC "-// SQL Map 2.0//EN" "" >
<sqlMap namespace="BLOB_TEST" >
  <insert id="insert_blob" parameterClass="java.util.HashMap" >
    insert into BLOB_TABLE (
    values (                                                                 

In this case, I am using a HashMap to pass in the data for the BLOB object. You can always use a value object instead.

// Get the SQL map client instance
SQLMapClient sqlMapclient = ....
// Retrieve the image in byte array
byte[] image = ...
// Construct the Map object and set the input image
Map dataMap = new HashMap();
dataMap.put("IMAGE", image);
// Insert into database
sqlMapClient.insert("insert_blob", dataMap);

Trackback URL

Sorry, comments for this entry are closed at this time.