You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Mithun Ruikar <mi...@yahoo.com> on 2005/02/15 20:42:48 UTC

How to set value to Blob field of derby-made-table.

Hello there , 
 
I have problem while setting Blob value to table created in derby.
I had created : a datasource by parameter create=true.
and then created new table in it with one column with Datatype as Blob.
 
But when I tried to setObject value to this column ( by serializable object awt.color)
It gave derby exception : trying to get Blob value from Object type.
 
setBlob also didnt work with error saying : this method is undefined for (int , Object)
and if i typecast it to (int , (Blob) Object) : I got classcastexception.
 
please tell me how to set this value to blob field
 
-- mithun
 

		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Re: How to set value to Blob field of derby-made-table.

Posted by Mithun Ruikar <mi...@yahoo.com>.
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....@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 abyte[] and then do a setBytes() ? And then to read itback you can do getBytes() and then deserialize fromthat byte[]. Would that work?Regards,Ali  

--- Mithun Ruikar <mi...@yahoo.com> wrote:  

Hello there ,  I have problem while setting Blob value to tablecreated in derby.I had created : a datasource by parametercreate=true.and then created new table in it with one columnwith Datatype as Blob. But when I tried to setObject value to this column (by serializable object awt.color)It gave derby exception : trying to get Blob valuefrom Object type. setBlob also didnt work with error saying : thismethod is undefined for (int , Object)and if i typecast it to (int , (Blob) Object) : Igot classcastexception. please tell me how to set this value to blob field -- mithun 		---------------------------------Do you Yahoo!? Yahoo! Search presents - Jib Jab's 'Second Term'    

  


		
---------------------------------
Do you Yahoo!?
 Yahoo! Search presents - Jib Jab's 'Second Term'

Re: How to set value to Blob field of derby-made-table.

Posted by Barnet Wagman <b....@comcast.net>.
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
>
>  
>
>--- Mithun Ruikar <mi...@yahoo.com> wrote:
>
>  
>
>>Hello there , 
>> 
>>I have problem while setting Blob value to table
>>created in derby.
>>I had created : a datasource by parameter
>>create=true.
>>and then created new table in it with one column
>>with Datatype as Blob.
>> 
>>But when I tried to setObject value to this column (
>>by serializable object awt.color)
>>It gave derby exception : trying to get Blob value
>>from Object type.
>> 
>>setBlob also didnt work with error saying : this
>>method is undefined for (int , Object)
>>and if i typecast it to (int , (Blob) Object) : I
>>got classcastexception.
>> 
>>please tell me how to set this value to blob field
>> 
>>-- mithun
>> 
>>
>>		
>>---------------------------------
>>Do you Yahoo!?
>> Yahoo! Search presents - Jib Jab's 'Second Term'
>>    
>>
>
>
>  
>


Re: How to set value to Blob field of derby-made-table.

Posted by Suavi Ali Demir <de...@yahoo.com>.
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


--- Mithun Ruikar <mi...@yahoo.com> wrote:

> Hello there , 
>  
> I have problem while setting Blob value to table
> created in derby.
> I had created : a datasource by parameter
> create=true.
> and then created new table in it with one column
> with Datatype as Blob.
>  
> But when I tried to setObject value to this column (
> by serializable object awt.color)
> It gave derby exception : trying to get Blob value
> from Object type.
>  
> setBlob also didnt work with error saying : this
> method is undefined for (int , Object)
> and if i typecast it to (int , (Blob) Object) : I
> got classcastexception.
>  
> please tell me how to set this value to blob field
>  
> -- mithun
>  
> 
> 		
> ---------------------------------
> Do you Yahoo!?
>  Yahoo! Search presents - Jib Jab's 'Second Term'