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
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Struts
how to store and retrieve an image to database using in struts
Julie Jacob
Greenhorn
Posts: 20
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi all,
How to store and retrieve an image in MySql using with
struts
. Anyone to know this please give me the solutions
thanks
Kerry Wilson
Ranch Hand
Posts: 254
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
First, the column type should be BLOB.
Second, your form property should be of type org.apache.struts.upload.FormFile
Third, in your action (assuming upload is name of property)
InputStream uploadIn = upload.getInputStream(); java.awt.Image image = javax.imageio.ImageIO.read(uploadIn); // Convert image to buffered image java.awt.image.BufferedImage imageBuffer = new java.awt.image.BufferedImage(image.getWidth(null),image.getHeight(null),BufferedImage.TYPE_INT_RGB); java.awt.Graphics imgGraphics = imageBuffer.getGraphics(); imgGraphics.drawImage(image,0,0,null); imgGraphics.dispose(); // Write to byte array output stream ByteArrayOutputStream out = new ByteArrayOutputStream(); ImageIO.write(imageBuffer,"jpg",out); // Setup stream for blob byte[] buffer = out.toByteArray(); ByteArrayInputStream inStream = new ByteArrayInputStream(buffer); Connection conn = getConnection(); PreparedStatement ps = conn.prepareStatement(SAVE_QUERY,PreparedStatement.RETURN_GENERATED_KEYS); ps.setBinaryStream( 1, inStream, inStream.available() ); ps.executeUpdate();
http://www.goodercode.com
SCJP 1.4
I've never won anything before. Not even a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
store an image to database and also retrieve
retrieving gif from database
how to store and retrieve files using blob
Displaying image blob in jsp using image tag
Struts and Multimedia
More...