ISQLWorker

Hi All,
I’ve a oracle table which has a BLOB column and an image needs to be stored.
Can anyone suggest a way to use ISQLWorker to insert the image as BLOB in the database table

I’d recommend using Integration Server for your Data Access Layer wherever possible, but below is some sample code.

The code expects that your database table has two columns with one column for the blob and the other column for a unique ID that you specify.

import java.sql.SQLException;

import com.webmethods.portal.service.meta2.IMetaContext;
import com.webmethods.portal.service.meta2.IMetaManager;
import com.webmethods.portal.service.meta2.MetaException;
import com.webmethods.portal.service.sql.ISqlWorker;
import com.webmethods.portal.system.PortalSystem;

public class DBTest {
    
    public void storeBLOBData(String tableName, 
                              String blobFieldName, 
                              byte [] bytes,
                              String keyFieldName,
                              int keyFieldValue) throws SQLException, MetaException{
        
        ISqlWorker worker = null;
        try {
            IMetaManager mm = (IMetaManager)PortalSystem.getMetaProvider();
            IMetaContext mc = mm.getDefaultContext();
            worker = mc.createWorker();
            worker.executeBlobUpdate(tableName, 
                    blobFieldName, 
                    bytes,
                    keyFieldName, 
                    new Integer(keyFieldValue));
            
            worker.commitTran();
        } finally {
            if (worker != null) {
                worker.release();
            }
        }
    }
}

[/code]