| | |
Displaying blob images from database and display it on jsp
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: May 2009
Posts: 4
Reputation:
Solved Threads: 0
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.
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
Can you guys provide examples of how to display the blob images from database?
Thanks
Hope to receive you guys reply asap!

I tried to add in the code that i think would display however it only display the path instead if the image.
JSP Syntax (Toggle Plain Text)
<%@ 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> </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
JSP Syntax (Toggle Plain Text)
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!
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
Have a look here http://simple.souther.us/ar01s10.html
![]() |
Similar Threads
- display random images from folder (PHP)
- Display images from database with Delete option. (PHP)
- how to display image in wml page using php (PHP)
- Displaying Thumbnail Images from Database (PHP)
- displaying mediumblob images using php (PHP)
- Displaying Images( buffered data ) from the Database using Java (Java)
- retrieving images from database in thumbnail form (PHP)
- Saving Images In Database (VB.NET)
Other Threads in the JSP Forum
- Previous Thread: Need help in running tomcat on fedora
- Next Thread: Server doesn't locate servlet. Help needed!
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web





