Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert an object into BLOB

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an XML file (or say any file)
I create an FileInputStream Object with it
Now I have to store this object in to database
I don't know whether I have to use CLOB or BLOB but
suppose I m using BLOB then how to convert it inot a BLOB object
do we have to use
setBlob(int x,Blob y)?
if yes then do we have to give FileInputStream Object as an argument for Blob object?
or is there any other alternative?
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gaurav,
That won't work, because your FileInputStream is attach to some external file on your harddrive. Let say you do save the FileInputStream object in the database, and reconstruct the object from the DB in your program at some later time in the future. Can you guaranty that the external file still exist and is in the same location?
A better approach is to read in the XML data, and store it in some application object. This object should then be serialized and stored in a BLOB or CLOB.
-Peter
 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one please tell how can we store our file in a BLOB or CLOB
setClob(int x,Clob y)
is a function
so wht argument shoud go for second parameter
I m still confused

Originally posted by Peter Tran:
Gaurav,
That won't work, because your FileInputStream is attach to some external file on your harddrive. Let say you do save the FileInputStream object in the database, and reconstruct the object from the DB in your program at some later time in the future. Can you guaranty that the external file still exist and is in the same location?
A better approach is to read in the XML data, and store it in some application object. This object should then be serialized and stored in a BLOB or CLOB.
-Peter

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic