Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 29th, 2009, 11:01 AM
Authorized User
Join Date: Jan 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to display out images from SQL Query Browser:(

Hello, I am peggie. Currently, I am using servlet to display out images on my image.jsp page. However, nothing appears.

This is my servlet code:
package sg.nyp.edu.sit;
import java.sql.*;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 * Servlet implementation class DisplayImage
public class DisplayImage extends HttpServlet {
 private static final long serialVersionUID = 1L;
     * Default constructor. 
    public DisplayImage() {
        // TODO Auto-generated constructor stub
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
  String connectionURL = "jdbc:mysql://localhost/images";
  java.sql.Connection con= null;
   con = DriverManager.getConnection(connectionURL,"root","");
   Statement st1=con.createStatement();
   ResultSet rs1 = st1.executeQuery("select image from images where imageID ='2'");
   String imglen="";
    imglen = rs1.getString(1);
   rs1 = st1.executeQuery("select image from images where imageID = '2'");
   if (rs1.next()){
    int len = imglen.length();
    byte[] rb = new byte [len];
    InputStream readImg = rs1.getBinaryStream(1);
    int index=readImg.read(rb,0,len);
    System.out.println("index" + index);
  catch (Exception e){
  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  // TODO Auto-generated method stub
This is my java getter and setter:
package sg.nyp.edu.sit.model;

public class Image {
int imageID;
Byte image;
String imglen;
public int getImageID() {
return imageID;
public void setImageID(int imageID) {
this.imageID = imageID;
public Byte getImage() {
return image;
public void setImage(Byte image) {
this.image = image;
public String getImglen() {
return imglen;
public void setImglen(String imgLen) {
this.imglen = imgLen;


This is my image.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<form name="form1" method="get" action="./DisplayImage">



My database is called: images
and the attributes are:
int imageID;
Blob image;

May I know what's wrong with it.
Hope to receive ur reply soon!:D
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to display sql server images in asp.net c# bobwith5 ASP.NET 2.0 Basics 0 October 20th, 2007 11:07 AM
Display text data in textarea from SQL query palvin Classic ASP Professional 13 November 30th, 2005 05:52 PM
Cannot display/return SQL Query Output from a Vari sjm SQL Server DTS 1 September 9th, 2005 11:40 AM
inserting images in ms sql server using query anal connect2sandep SQL Server 2000 2 July 24th, 2005 04:41 PM
Unable to create SQL Query using parameters odyzeus Crystal Reports 0 March 3rd, 2005 01:29 PM

All times are GMT -4. The time now is 09:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.