aspose file tools*
The moose likes JDBC 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
Bookmark "how to store image object" Watch "how to store image object" New topic
Author

how to store image object

wesley arun
Greenhorn

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
Wesley

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
http://doinfinite.com
wesley arun
Greenhorn

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

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


Wesley
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30776
    
157

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


[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
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()) {
f.mkdir();
}
InputStream stream = fileForUpload.getInputStream();
path += "/" + fileName;
OutputStream bos = new FileOutputStream(path);
int temp = 0;

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

bos.close();
stream.close();

}catch(IOException ioEx){

}
return path;
}
 
wood burning stoves
 
subject: how to store image object