Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
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:
JDBC and Relational Databases
Retrieving blob object
sovan chatt
Ranch Hand
Posts: 43
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SrServlet extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{ String fname=request.getParameter("fid"); try{ Connection con=DbCon.setCon(); PreparedStatement p=con.prepareStatement("SELECT PIC FROM TEST WHERE PNAME=?"); p.setString(1, fname); ResultSet rs1=p.executeQuery(); InputStream readImg=null; byte[] rb=null; if(rs1.next()){ rb = rs1.getBytes(1); readImg = rs1.getBinaryStream(1); } con.close(); response.reset(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,readImg.available()); response.getOutputStream().flush(); } catch (Exception e){ e.printStackTrace(); } } }
In an html page I'm giving the file id..and when I click the 'SEARCH ' button this
servlet
gets called.. But weirdly whenever I click the "SEARCH" button I am getting a security warning about file download!!
Abhishek Ralhan
Ranch Hand
Posts: 40
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
That is what the above code will do..
Do you want to display the search results instead??
-Abhishek
I came to this world on a Learner's License
sovan chatt
Ranch Hand
Posts: 43
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
@Abhishek Ralhan I want to display the image that I stored as a blob object in the database...
Abhishek Ralhan
Ranch Hand
Posts: 40
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Sovan,
THis is what I got when i Googled,
http://fdegrelle.over-blog.com/article-992927.html
http://www.theserverside.com/discussions/thread.tss?thread_id=5444
please see and help yourself..
-Abhishek
I came to this world on a Learner's License
Michael Angstadt
Ranch Hand
Posts: 282
I like...
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Like Abhishek's links suggest, try calling this servlet from an img tag:
<img src="servlet/url?fid=1234" />
SCJP 6 || SCWCD 5
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Display Image in JSP retrieved from database by servlet
Displaying an image from byte[] into JSP
servlet not running
displaying image from database
display image after retrieving it from database?
More...