Board index » jbuilder » Re: Inserting a BLOB in Oracle database

Re: Inserting a BLOB in Oracle database


2006-02-04 05:34:16 PM
jbuilder1
Roger Boisjoli wrote:
Quote
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:

I do not know about Sybase, but in Oracle, would have to use the Oracle Blob
type and tyupecast it back to a java.sql.Blob type
for instance
oracle.sql.Blob blob= (oracle.sql.Blob) rs.getBlov("SomeColumnName");
//inserting back
ps.setBlob(1,java.sql.Blob)blob);
Another thing,
To get a blob open for access, in Oracle, you need to do a "Select for
Update". This one drove me nuts, the first time I attempted it.
 
 

Re:Re: Inserting a BLOB in Oracle database

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
 

Re:Re: Inserting a BLOB in Oracle database

Roger Boisjoli wrote:
Quote
This line gives me an error:
int pic_len = pic_blob.setBytes(1, datafile);
The error is : Unsupported feature.
I found a couple links on Google that might help (watch for line wrapping
of the URLs):
saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi
asktom.oracle.com/pls/ask/f
Here's my search:
www.google.ca/search&meta=
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/
NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
www.datadevelopment.com/papers/index.html
Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html
 

{smallsort}