Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

how to get the content from BLOB datatype in java

HI Experts,

I have  a table in database for that table one of the column is of type BLOB.
this column contains some data. how to get the data from this column.
Can any one suggest how to do
Thanks
Avatar of CPColin
CPColin
Flag of United States of America image

Use ResultSet.getBlob() to get the Blob object and then call Blob.getBytes() or Blob.getBinaryStream() to get the bytes or an InputStream that you can read from to get the bytes.

You can also call getBinaryStream() on the ResultSet object directly.
Avatar of srikotesh
srikotesh

ASKER

i am not using result set

i am getting the value from the database
now i have to get the value

Object master = dao.getTableDetails();
if(master ! = null)
{
//here i have to get the value
byte[] data =(Blob) row[0];
//here i am getting class cast exception
}
Blob blobdata = (Blob) row[0];
byte[] data = blobdata.getBytes()

i have tried like this also
What type of object is that row variable?
blob type
SOLUTION
Avatar of CPColin
CPColin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
can you post your full code listing.
from the database I am getting data type as byte array,not blob.
I have converted that byte array to blob then I converted blob to string.
from the database I am getting data type as byte array,not blob.
I have converted that byte array to blob then I converted blob to string.

So you solved it yourself?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi CPcolin,
Yes issue is resolved.

Hi gheist,
That might be the reason .
You worked around the issue, which is good result. If you do not intend to fix BLOB support in your DB you can close now.
i found solution my own with the help of CPcolin.