GeeCON Prague 2014*
The moose likes I/O and Streams and the fly likes How to convert an object into BLOB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to convert an object into BLOB" Watch "How to convert an object into BLOB" New topic
Author

How to convert an object into BLOB

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
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?

SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
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

Joined: Jun 09, 2000
Posts: 410
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert an object into BLOB