🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.database
Article #284

Inserting a BLOB in Oracle database

#284
From: Roger Boisjoli
Date: Sat, 04 Feb 2006 14:17
100 lines
4557 bytes
I am using JBuilder with Sybase EAServer (Jaguar) to access an Oracle 8i
dtabase and need to insert images into a Blob.

I have the following code:

  public void updWFRSystem(WFRSystemsVO system) throws DAOException {

    PreparedStatement pstmt = null;
    ResultSet rs;
    Blob pic_blob = null;
    String sql = this.UPD_SYSTEM_SQL;
    Connection conn = getConnection();
    byte[] datafile = system.getSystem_pic();
    ByteArrayInputStream bdatafile = new ByteArrayInputStream(datafile);

    logger.info("***WFR--Updating System with System ID : " +
system.getSystem_ID());
    try {
      pstmt = conn.prepareStatement(this.GET_SYSTEM_SQL);
      pstmt.setInt(1, Integer.parseInt(system.getSystem_ID()));
      rs = pstmt.executeQuery();
      rs.next();
      pic_blob = rs.getBlob("system_pic");
      close(pstmt);
      logger.debug("***WFR--Preparing SQL");
      pstmt = conn.prepareStatement(sql);
      pstmt.setInt(1, Integer.parseInt(system.getCategory_ID()));
      pstmt.setString(2, system.getSystem_Code());
      pstmt.setString(3, system.getSystem_Descr());
      pstmt.setString(4, system.getEac_code());
      pstmt.setInt(5, Integer.parseInt(system.getLcmm_id()));
      pstmt.setInt(6, Integer.parseInt(system.getOpi_id()));
      System.out.println("Picture Size : " +
system.getSystem_pic().length);
      int pic_len =  pic_blob.setBytes(1, datafile);
      System.out.println("Length of blob : " + pic_len);  // I get the
right length for the file.
      if (pic_len == 0) {
        logger.error("***WFR--The picture length was zero when in
updWFRSystem, "
                     + "which is the expected amount.");
        throw new WFRDAOException("The picture length was zero when in "

                                  + "updWFRSystem, which is the expected
amount.");
      } else
        pstmt.setBlob(7, pic_blob);
      pstmt.setInt(8, Integer.parseInt(system.getSystem_ID()));
      int update = pstmt.executeUpdate();
      if (update != 1) {
        logger.error("***WFR--The update count was not 1 when in
updWFRSystem, "
                     + "which is the expected amount.  Count was : " +
update);
        throw new WFRDAOException("The update count was not 1 when in "
                                  + "updWFRSystem, which is the expected
amount."
                                  + "  Count was : " + update);
      }
    }
    catch (SQLException ex) {
      logger.error("***WFR--SQL Exception was thrown in updWFRSystem. "
                   + "The error message is: " + ex.getMessage(), ex);
      throw new WFRDAOException("SQL Exception was thrown in
updWFRSystem.  "
                                + "The error message is: " +
ex.getMessage(), ex);

    }
    finally {
      close(pstmt);
      close(conn);
    }
  }

This line gives me an error:
      int pic_len =  pic_blob.setBytes(1, datafile);
The error is : Unsupported feature.

I have the following imports:
import langui.business.dao.*;
import WFR.business.vo.WFRSystemsVO;
import WFR.business.vo.WFRSitesVO;
import WFR.business.dao.IWFRSitesDAO;
import org.apache.commons.logging.LogFactory;
import javax.sql.*;
import java.sql.*;
import WFR.business.exception.WFRDAOException;
import langui.business.exceptions.DAOException;
import WFR.business.JNDINames;
import java.sql.ResultSet;
import org.apache.commons.logging.Log;
import java.sql.PreparedStatement;
import java.sql.Types;
import java.util.Vector;
import java.io.*;

Why am I getting this error?

Roger Boisjoli
Technical Details
Message-ID: <43E4B77D.E8371F85@netscape.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!atl-c05.usenetserver.com!news.usenetserver.com!indigo.octanews.net!news-out.octanews.net!teal.octanews.net!nx01.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1073da,8a91b04e7647579,start
X-Google-Attributes: gid1073da,public
X-Google-Language: ENGLISH,ASCII-7-bit
Message-ID: <43E4B77D.E8371F85@netscape.net>
Date: Sat, 04 Feb 2006 08:17:33 -0600
From: Roger Boisjoli <RHJBoisjoli@netscape.net>
X-Mailer: Mozilla 4.72 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.database
Subject: Inserting a BLOB in Oracle database
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 142.161.126.169
X-Trace: newsgroups.borland.com 1139062237 142.161.126.169 (4 Feb 2006 06:10:37 -0700)
Lines: 102
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!atl-c05.usenetserver.com!news.usenetserver.com!indigo.octanews.net!news-out.octanews.net!teal.octanews.net!nx01.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail