Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Struts
store an image to database and also retrieve
Julie Jacob
Greenhorn
Posts: 20
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
How I store an image to database and also retrieve an image from database to
struts
based
jsp
page .
anyone to help me
thanks
Kerry Wilson
Ranch Hand
Posts: 254
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have already given you a fairly comprehensive code piece of how this is done:
https://coderanch.com/t/51874/Struts/store-retrieve-image-database-struts
To retrieve:
Of course the following code needs to be in a
servlet
of some sort.
// Retrieve from database Connection conn = getConnection(); PreparedStatement ps = conn.prepareStatement(GET_QUERY); ps.setInt( 1, imageId ); ResultSet rs = ps.executeQuery(); java.awt.Image img = null; if( rs.next() ) { Blob imgBlob = rs.getBlob("imageBlob"); InputStream input = imgBlob.getBinaryStream(); img = ImageIO.read(input); } conn.close(); rs.close(); ps.close(); // Output to browser BufferedImage bufferedImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics imgGraphics = bufferedImg.getGraphics(); imgGraphics.drawImage(image,0,0,width,height,null); imgGraphics.dispose(); response.setContentType("image/jpeg"); ServletOutputStream out = response.getOutputStream(); com.sun.image.codec.jpeg.JPEGImageEncoder je= JPEGCodec.createJPEGEncoder(out); je.encode(bufferedImg); out.close();
http://www.goodercode.com
SCJP 1.4
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
retrieving gif from database
Image retreival from oracle and display in java
servlets and images???
Storing/retrieving files in/from sql server thru java
inserting image
More...