• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to store image object

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


 
wesley arun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ram,

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


Wesley
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#2 is covered in the JDBC tutorial. #1 is just Java code. What are you looking for, the File I/O libraries?
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic