File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes storing images in the database 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 images in the database" Watch "storing images in the database" New topic

storing images in the database

sushant prabhu
Ranch Hand

Joined: Mar 22, 2001
Posts: 66
i dont know wheteher to post this query here or i dont know about any oracle forum i am posting my query here.
Actually i want to store images/music or video in the oracle database. I hav read that u can acheive this with blobs.
But i hav also read that u require an appropriate convertor before storing it into the databse.
How do i go about it . can somebody please guide.
i also want to know about an oracle forum where i can post my queries. it would be helpful if somebody culd redirect me to any.

Sushant Prabhu<br />SCJP2<br />SCWCD<br />OCA9i
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Two suggestions:
1) Do a search for "blob" in this forum
2) check

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog

Joined: Apr 07, 2001
Posts: 18
u can do something like this ..hope u will get it ..
import these ...
import java.util.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
insert an empty row in the table like this
stmt.executeUpdate("insert into blobdata (blob_nr,data) values ("+ +blobnr + " ,empty_blob())");
now u do just like this ..
ResultSet rs2;
BLOB blob=null ;
Stringcmd = "SELECT inhalt FROM blobdata WHERE blob_nr=" +blobnr + " for update";
rs2 = stmt.executeQuery(cmd);
blob= ((OracleResultSet)rs2).getBLOB(1);
//filling blob
File binaryFile = new File("fileName);
FileInputStream instream = new FileInputStream(binaryFile);
OutputStream outstream = blob.getBinaryOutputStream();

int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
while ((length = != -1)
outstream.write(buffer, 0, length);

hope u can figure it out ..
if not then ask i will be happy to clarify it ..
slagy maggie
Ranch Hand

Joined: Feb 20, 2001
Posts: 35
Need help!!!
i have a string, i have to store this in the database as type text....which means i have to save it as a type BLOB
how do i go about cvonverting the string to BLOB???
i am using informix as my database
and java as my application program
Maheshwari J

Joined: Aug 13, 2001
Posts: 3
Actually i am able to store gif files into the oracle BLOB.
but i dont know how to retrieve the gif file from BLOB and display the gif in the browser
I agree. Here's the link:
subject: storing images in the database
jQuery in Action, 3rd edition