Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes how to store image object 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 "how to store image object" Watch "how to store image object" New topic

how to store image object

wesley arun

Joined: Sep 30, 2004
Posts: 3
Dear Pals,

Well i have a jsp application to capture some data and store it in the oracle DB, but i need some image object to capture along with the existing data.

Do i have to create a blob object in my oracle DB, and if so how to insert the image object. Or is there anyway i can store it in the webserver, if so how.

I will be grateful if anybody help me in this regards.

Thanks In Advance

Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
first option
You can upload and save images to a folder. No need to put images in DB.

second option
You can create a blob in DB and write the binaries in it.

Ram Parashar
wesley arun

Joined: Sep 30, 2004
Posts: 3
Thanks Ram,

well can you give me a sample code how to accomplish both the option.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

#2 is covered in the JDBC tutorial. #1 is just Java code. What are you looking for, the File I/O libraries?

[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
Ram Para
Ranch Hand

Joined: Jul 09, 2008
Posts: 50
This is an Struts code for file upload.

Here I am saving the file to an directory. You can change the path to some other folder. like in C:\abc folder

You can easily modify the code.

try this

DynaActionForm dynaForm = (DynaActionForm) form;
FormFile fileForUpload = (FormFile) dynaForm.get("fileToUpload");
String path = request.getSession().getServletContext().getRealPath(FILE_UPLOAD_PATH);
path = uploadExcelSheet(path, fileForUpload);

private String uploadExcelSheet(String path, FormFile fileForUpload){
try {
String fileName = fileForUpload.getFileName();

File f = new File(path);
if (!f.isDirectory()) {
InputStream stream = fileForUpload.getInputStream();
path += "/" + fileName;
OutputStream bos = new FileOutputStream(path);
int temp = 0;

byte[] buffer = new byte[8192];
while ((temp =, 0, 8192)) != -1) {
bos.write(buffer, 0, temp);


}catch(IOException ioEx){

return path;
I agree. Here's the link:
subject: how to store image object
jQuery in Action, 3rd edition