wood burning stoves *
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "BLOB data type" Watch "BLOB data type" New topic
Author

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?

Thanks,
Trupti
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
Shailesh,

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?

Thanks,
Trupti
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
Hello,

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.
Thanks,
Trupti
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31119
    
166

Trupti,
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
Greenhorn

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