BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Inserting a BLOB in Oracle database

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder Databases
View previous topic :: View next topic  
Author Message
Roger Boisjoli
Guest





PostPosted: Sat Feb 04, 2006 7:17 pm    Post subject: Inserting a BLOB in Oracle database Reply with 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:

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
Back to top
Paul Nichols (TeamB)
Guest





PostPosted: Sat Feb 04, 2006 7:17 pm    Post subject: Re: Inserting a BLOB in Oracle database Reply with quote



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.
Back to top
Kevin Dean [TeamB]
Guest





PostPosted: Sat Feb 04, 2006 7:54 pm    Post subject: Re: Inserting a BLOB in Oracle database Reply with quote



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

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=3&t=007947


http://asktom.oracle.com/pls/ask/f?p=4950:8:16080386247738967728::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6379798216275

Here's my search:

http://www.google.ca/search?hl=en&q=Blob+%22Unsupported+feature%22&meta=

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.