This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes BLOB data type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "BLOB data type" Watch "BLOB data type" New topic

BLOB data type

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 613
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: 1081

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

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

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
internet detective

Joined: May 26, 2003
Posts: 30057

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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:
subject: BLOB data type
Similar Threads
how to create BLOB and CLOB data
getblob from db, then convert to byte and write to bitmap/jpeg
how to write BLOB type of data from java application into an oracle table
Excel File opening
java.sql.SQLException: Unsupported feature