View Single Post
  #4  
Old 07-18-2009, 06:56 AM
peggie1990 peggie1990 is offline
New Member
 
Join Date: Jul 2009
Posts: 9
Default Displaying blob images from database instead of the url.

Hey guys do you have any idea on displaying blob images from the database instead of displaying the blob url path.And the images display should come with the details like the image is yellow beanie, the color is yellow...

This is my code:

Code:
<%@ 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><%@ 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>
However when I debug the images is only show the blob url

And this is my expected outcome if the blob is able to work

Thanks.
Attached Images
File Type: jpg 1.jpg (30.2 KB, 3 views)
Reply With Quote