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.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>PRODUCTS DETAILS</h1>
<p>
<%
				//Retrieve the id of the product selected by the user
				//the product id is sent via the URL as a parameter
				int ProductId = -1;
				String strProductId = request.getParameter("ProductId");
				if(strProductId != null) {
					//Convert from string to int
					ProductId = Integer.parseInt(strProductId);
				}
				
				//Load the database driver
		       	Class.forName("com.mysql.jdbc.Driver");
				//Create a connection to our database
		       	Connection con = DriverManager.getConnection("jdbc:mysql://localhost/peisze", "root", "");
				//create an SQL statement
		       	PreparedStatement ps = con.prepareStatement("SELECT * FROM products WHERE ProductId=?");
				//set the ID to be the id above
		       	ps.setInt(1, ProductId);
				//Execute and retrieve our result
		       	ResultSet rs = ps.executeQuery();
			%>
</p>
<%
        	//if there is a result, rs.next() will be true
        	//else it will be false
			if(rs.next()) {
		%>
<fieldset>
<legend>Product Information</legend>
<table border="0">
	<tr>
		<td>
		<div align="left">Image: <%=rs.getBlob("ProdImage")+"\t" %></div>
		</td>
		<td>Product Name: <%=rs.getString("ProdName")+"\t" %>

		<div align="left">Product Color: <%=rs.getString("ProdColor")+"\t" %></div>

		<div align="left">Product Description: <%=rs.getString("ProdDesc")+"\t" %></div>

		<div align="left">Product Price: <%=String.format("$%.2f",rs.getDouble("UnitPrice"))+"\t" %></div>

		<div align="left">Quantity: <%=rs.getString("Quantity")+"\t" %></div>
		
	
		
	    

		</td>
	</tr>
</table>
</fieldset>

<%
			}
			else {
				//if no record is found, simply display a no record message
		%>
No record found.
<%
			}
		 %>
<p>&nbsp;</p>


</body>
</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

Product Information
Image: com.mysql.jdbc.Blob@78aa80  
Product Name: Yellow Beanie 
Product Color: Yellow 
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. 
Product Price: $30.00 
Quantity: 10

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

Thanks:)
Hope to receive you guys reply asap!:D

Recommended Answers

All 2 Replies

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:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.