File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Storing file in oracle databse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Storing file in oracle databse" Watch "Storing file in oracle databse" New topic
Author

Storing file in oracle databse

Prashant Satarkar
Greenhorn

Joined: Jan 02, 2003
Posts: 12
Hi All,
I have to store files, like .html, .gif, .jpg, .txt etc in the database. I mean not only the content, but the entire file with name.
Also, I want to retrieve it with name and full content.
Any idea how exactly will I be able to do it?
Should I use FileInutStream and convert it to ByteArrayInputStream and store it as bytes[] ?
Then, again convert byte array to file input stream and file object?
Thanks in advance,
Prashant
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Have a look at the blob and clob types. They should forfill your needs
Regards
Nigel
Prashant Satarkar
Greenhorn

Joined: Jan 02, 2003
Posts: 12
Hi all thanks Nigel. I think my qs was very brief. i have to store images .gif/.jpg in the database using Java.
I am exploring the following options:
1. Converting the images to Byte Array and storing in the CLOB field in Database. Its not ahppening as it gives teh following error: "ORA-01461: can bind a LONG value only for insert into a LONG column".
If I try inserting a string "abc".getBytes(), its not giving any problem and i am able to insert it.
2. The other option is using BLOB. I am trying that out but have no idea how to do this? Please let me know how can I use the BLOB field and insert images .gif/.jpg into it using Java
Thanks,
Prashant
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30353
    
150

Prashant,
It is better to use BLOB. Blob is meant for binary data (which is what you have) while clob is meant for character data.
Sun has a tutorial that explains it.
[ March 24, 2004: Message edited by: Jeanne Boyarsky ]

[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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Storing file in oracle databse