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 "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="BLOB_TEST" >
 
  <insert id="insert_blob" parameterClass="java.util.HashMap" >
    insert into BLOB_TABLE (
      IMAGE)
    values (                                                                 
      #IMAGE:BLOB#)
  </insert>
 
</sqlMap>

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);

Popularity: 2% [?]


Trackback URL


RSS Feed for This Post1 Comment(s)

  1. Vijayalakshmi | Jun 28, 2010 | Reply

    How to get a Oracle blob object using iBATIS?

RSS Feed for This PostPost a Comment