Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Storing file in oracle databse" Watch "Storing file in oracle databse" New topic

Storing file in oracle databse

Prashant Satarkar

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,
Nigel Browne
Ranch Hand

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

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
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33107

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 ]

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Storing file in oracle databse
jQuery in Action, 3rd edition