• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BLOB data type

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use setblob method of java.sql.preparedstatement

hope this helps.
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic