Displaying blob images from database and display it on jsp

Reply

Join Date: May 2009
Posts: 4
Reputation: peggie1990 is an unknown quantity at this point 
Solved Threads: 0
peggie1990 peggie1990 is offline Offline
Newbie Poster

Displaying blob images from database and display it on jsp

 
0
  #1
Jul 15th, 2009
Hey, I really need you guys help as I had been searching info on displaying blob images from database for weeks

I tried to add in the code that i think would display however it only display the path instead if the image.

  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <%@ page import="java.sql.*"%>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  8. <title>Insert title here</title>
  9. </head>
  10. <body>
  11. <h1>PRODUCTS DETAILS</h1>
  12. <p>
  13. <%
  14. //Retrieve the id of the product selected by the user
  15. //the product id is sent via the URL as a parameter
  16. int ProductId = -1;
  17. String strProductId = request.getParameter("ProductId");
  18. if(strProductId != null) {
  19. //Convert from string to int
  20. ProductId = Integer.parseInt(strProductId);
  21. }
  22.  
  23. //Load the database driver
  24. Class.forName("com.mysql.jdbc.Driver");
  25. //Create a connection to our database
  26. Connection con = DriverManager.getConnection("jdbc:mysql://localhost/peisze", "root", "");
  27. //create an SQL statement
  28. PreparedStatement ps = con.prepareStatement("SELECT * FROM products WHERE ProductId=?");
  29. //set the ID to be the id above
  30. ps.setInt(1, ProductId);
  31. //Execute and retrieve our result
  32. ResultSet rs = ps.executeQuery();
  33. %>
  34. </p>
  35. <%
  36. //if there is a result, rs.next() will be true
  37. //else it will be false
  38. if(rs.next()) {
  39. %>
  40. <fieldset>
  41. <legend>Product Information</legend>
  42. <table border="0">
  43. <tr>
  44. <td>
  45. <div align="left">Image: <%=rs.getBlob("ProdImage")+"\t" %></div>
  46. </td>
  47. <td>Product Name: <%=rs.getString("ProdName")+"\t" %>
  48.  
  49. <div align="left">Product Color: <%=rs.getString("ProdColor")+"\t" %></div>
  50.  
  51. <div align="left">Product Description: <%=rs.getString("ProdDesc")+"\t" %></div>
  52.  
  53. <div align="left">Product Price: <%=String.format("$%.2f",rs.getDouble("UnitPrice"))+"\t" %></div>
  54.  
  55. <div align="left">Quantity: <%=rs.getString("Quantity")+"\t" %></div>
  56.  
  57.  
  58.  
  59.  
  60.  
  61. </td>
  62. </tr>
  63. </table>
  64. </fieldset>
  65.  
  66. <%
  67. }
  68. else {
  69. //if no record is found, simply display a no record message
  70. %>
  71. No record found.
  72. <%
  73. }
  74. %>
  75. <p>&nbsp;</p>
  76.  
  77.  
  78. </body>
  79. </html>

This is the code that I used to display all those information of my products including the details of the products like name, color,etc...

However the outout is:

PRODUCTS DETAILS

  1. Product Information
  2. Image: com.mysql.jdbc.Blob@78aa80
  3. Product Name: Yellow Beanie
  4. Product Color: Yellow
  5. Product Description: FEPPZ© label was derived from FEPPZ COMPANY and is inspired by the smart and casual style with a chic look for modern female! This beanie style headwear is vibrant in color that can lift one spirit up.
  6. Product Price: $30.00
  7. Quantity: 10


Can you guys provide examples of how to display the blob images from database?

Thanks
Hope to receive you guys reply asap!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 316
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 51
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz

Re: Displaying blob images from database and display it on jsp

 
0
  #2
Jul 15th, 2009
You shouldnt be connecting to a database from a jsp page, rather use a servlet.

Have a look here http://simple.souther.us/ar01s10.html
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 4
Reputation: peggie1990 is an unknown quantity at this point 
Solved Threads: 0
peggie1990 peggie1990 is offline Offline
Newbie Poster

Re: Displaying blob images from database and display it on jsp

 
0
  #3
Jul 15th, 2009
Thanks
But the code that I had input in is at the jsp page. Hmm do you have another example that show the details as well as information?
thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC