wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes BLOB data type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "BLOB data type" Watch "BLOB data type" New topic

BLOB data type

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 614
Hello all,

I have a Db table that has a column which is of type BLOB.
I am using oracle and java for development.
Does anyone know how to insert the BLOB object into DB. BLOB matches to what data type in java?

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

use setblob method of java.sql.preparedstatement

hope this helps.

Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 614

I am trying to insert String into BLOB type column.
Do i need to process it before inserting to DB,i mean need to chnge it to different data type?

Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
i think its obvious. haven't tried to insert string into blob type, though. did with bytes and it went fine.
trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 614

I am trying to insert String into CLOB type column like below.
pstmt.setObject(10, msg,java.sql.Types.VARCHAR);

where msg is String.
I am getting SQLException which says inserted value too large.
I tried to insert in different way like below .

byte[] bytes = msg.getBytes();
ByteArrayInputStream byteStream = new ByteArrayInputStream (bytes);
pstmt.setAsciiStream(10, byteStream, bytes.length);

but still getting the same exception.
Can someone please help me.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

How big is the BLOB?

Also, why are you using an ASCII stream rather than a Binary one? A BLOB is for binary data. A CLOB is for character data.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Prashant Jain

Joined: Aug 19, 2004
Posts: 29
Instead of doing setObject trying setting the stream right away in case of Blobs.I have been able to set them this way for both Oracle and SQL Server.
I agree. Here's the link: http://aspose.com/file-tools
subject: BLOB data type
It's not a secret anymore!