aspose file tools
The moose likes JDBC and the fly likes BLOB data type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "BLOB data type" Watch "BLOB data type" New topic
Author

BLOB data type

trupti nigam
Ranch Hand

Joined: Jun 21, 2001
Posts: 603
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: 1076

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: 603
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: 603
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 26496
    
  78

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
 
Similar Threads
java.sql.SQLException: Unsupported feature
how to create BLOB and CLOB data
Excel File opening
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