db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig Russell <Craig.Russ...@Sun.COM>
Subject Re: How to invoke methods of Blob interface
Date Sat, 19 Feb 2005 18:24:52 GMT
Hi Mithun,

I think that Barnet was talking about using the PreparedStatement 
interface and avoiding the Blob interface entirely.

That is,

PreparedStatement ps = conn.PrepareStatement("insert into EMPLOYEE(ID, 
IMAGE) values(?,?)");
ps.setInt(1, id);
byte[] b = ... // serialize arbitrary object to byte[]
ByteArrayInputStream ins = new ByteArrayInputStream(b);
ps.setBinaryStream(2, ins, b.length);
int result = ps.executeUpdate();

You can use a similar technique on input, using the getBinaryStream 
method of ResultSet. The binary stream methods of PreparedStatement and 
ResultSet are highly portable across vendors.

Craig

On Feb 18, 2005, at 9:37 PM, Mithun Ruikar wrote:

> Hello ,
>   
> Barnet Wagman replied me , to use setBinaryStream method of Blob 
> interface.
> But How can I instantiate Blob object , as it is interface and I dont 
> know it's implemetation ?
>  
> How I can get blob object to call setBinaryStream.
>  
> that is :
> ps.setBinaryStream(psParamIndex, ins, b.length);
> from where you got this ps and what is the value of psParamIndex.
>
> thank you
>
>  -- mithun
> Barnet Wagman <b.wagman@comcast.net> wrote:
> I always serialize the object to a byte[]  and then use 
> setBinaryStream(), e.g.
>
> byte[] b = ... // serialize arbitrary object to byte[]
>
> ByteArrayInputStream ins = new ByteArrayInputStream(b);
> ps.setBinaryStream(psParamIndex, ins, b.length);
>
> I've found this to be reliable. FYI Problems with using setObject () 
> with blobs is not
>  specific to Derby.  I've had to use the above with MySQL and Oracle 
> as well.
>
> bw
>
> Suavi Ali Demir wrote:
> How about you first serialize your object into a
> byte[] and then do a setBytes() ? And then to read it
> back you can do getBytes() and then deserialize from
> that byte[]. Would that work?
> Regards,
> Ali
>
>
>  __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!

Mime
View raw message