Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BLOB data type

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use setblob method of java.sql.preparedstatement

hope this helps.
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34408
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prashant Jain
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic