Solved

Upload Image into Oracle Database using JSP

Posted on 2004-08-23
5
1,274 Views
Last Modified: 2008-03-06
Hi, I would like to upload different type of images from the server (C:\) and save it to the database. Anyone can give me sample codes or advise me? Thanks!
0
Comment
Question by:mwcmp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 11868439
>  Hi, I would like to upload different type of images from the server

Upload from the server?

I guess you mean you want people to be able to select an image on their client machine, then upload it into the oracle database?

Ok, for the uploading, you will need this:

http://jakarta.apache.org/commons/fileupload/

There are examples in the download on how to use it to upload files (through the <input type="file"> html tag)

Then, for storing the images in the database, you will need to use a BLOB field:

http://www.experts-exchange.com/Databases/Oracle/Q_20935767.html

HOWEVER!!!  I can recommend NOT doing this, and storing the image on the server's harddisk, and just placing a the file location in the database.  This has the advantage that the database will stay smaller, you will not have to extract the image and work out a file name for it to display it in your webapplication, and you will be able to backup all of the images and databse quicker.  It will also be easier to debug, and extend at a later date.

I'd basically store the images inside a folder accessable to your webapplication, then store the relative path to those images in the database as a standard VARCHAR field...

Tim
0
 

Author Comment

by:mwcmp
ID: 11879780
I'd basically store the images inside a folder accessable to your webapplication, then store the relative path to those images in the database as a standard VARCHAR field...


I get your point, but can you show me some concrete examples to show me? Thanks!
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11879811
Ok, use the FileUpload library I gave you in the first link...  There are examples in there to show you how it works...

Then, if your webapp is inside:

  tomcat/webapps/ROOT

Save the uploaded image file to

  tomcat/webapps/ROOT/uploads

Giving it a filename by using File.createTempFile (so that you don't have problems with 3 people uploading a file with the same name)

Then, store into the database "/uploads/fil019101.gif" (assuming "fil019101.gif" is the name the createTempFile returned)

Then, in your webapplication, to point to the image, and display it, you can simply put this string into a <img src="XXX"> tag (at the XXX location, and it will display in the browser...

You can also store the original filename in the database, so people can see what it was called, and not your temporary file name :-)

Hope this is what you meant :-)

Tim
0
 

Author Comment

by:mwcmp
ID: 11902883
http://jakarta.apache.org/commons/fileupload/

What should I download? I don't understand how it works!
0
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 11902975
http://ftp.plig.net/pub/apache/dist/jakarta/commons/fileupload/binaries/commons-fileupload-1.0.zip

Then you can add the

    commons-fileupload-1.0.jar

to your

    WEB-INF/lib

directory (in your webapplication in Tomcat)

And this document goes through how to use it :-)

http://www.onjava.com/pub/a/onjava/2003/06/25/commons.html?page=last&x-maxdepth=0
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
Set up Wildfly 10 8 448
maven webservice example issue 2 157
How  Can  I  resolve   this  Error "java.sql.SQLException: Invalid column index" 4 56
Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for…
In order to fulfill our mission of inspiring learning in the technology community, Experts Exchange is launching a Course of the Month program. Premium and Team Account members will have access to one course per month as a part of their membership, …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question