Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve Images from oracle

 
Maheshwari J
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have stored image files in a database. Is there any way to display that image in a web browser by querying the database?
 
Nathan KV
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No way !
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that an <IMG SRC="gifserver.jsp?imagename=a_db_key"> type of tag would work. Your "gifserver.jsp" would have to extract the data from the database and return a response type (MIME type) of a GIF image.
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A servlet is actually much better suited to doing this kind of work. Here is some example code I found:
public void doGet (HttpServletRequest req, HttpServletResponse res)
�������throws ServletException, IOException {
�������OutputStream out = res.getOutputStream();
�������String fileName = req.getParameter("image");
�������res.setContentType("image/jpeg");
// I'm not sure this line is quite right
String realPath = context.getRealPath(image);
�������FileInputStream in = new FileInputStream(readPath);
// i'm also not convinced this is the best
// way of doing this
�������int i;
�������while ((i = in.read()) != -1) {
�����������out.write(i);
�������}
�������in.close();
�������out.close();
}
 
Raghav
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maheshwari J:
I have stored image files in a database. Is there any way to display that image in a web browser by querying the database?

Hi,
I think these links show how to insert and retrive images from a database ,i hope this will be helpful for u
http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBPut/index.html
http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBGet/index.html
regards
raghav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic