Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7750831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:23:32+00:00 2026-06-01T11:23:32+00:00

ShowImage.java /* * To change this template, choose Tools | Templates * and open

  • 0

ShowImage.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package form;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CriminalPic extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "epolicia", "admin");
           PreparedStatement ps = con.prepareStatement("select * from CRIMINAL_PIC where CRIMINAL_ID = ?");
            String id = request.getParameter("id");
            ps.setString(1,id);
            ResultSet rs = ps.executeQuery();
            rs.next();
            Blob  b = rs.getBlob("PICTURE");
            response.setContentType("image/jpeg");
            response.setContentLength( (int) b.length());
            InputStream is = b.getBinaryStream();
            OutputStream os = response.getOutputStream();
            byte buf[] = new byte[(int) b.length()];
            is.read(buf);
            os.write(buf);
            os.close();
        }
        catch(Exception ex) {
            PrintWriter out = response.getWriter();
             out.print("../pics/thief.jpg");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
}

show.jsp

<%out.print("<img width='100%' height='200' src=../CriminalPic?id=" +rs.getString(1) + "></img>");%>

I’m trying to display the image from the database using Servlet. It works fine, but for the alternative, when it got any exception, for that case, it must show the alternative image, whose path has been given. But, it doesn’t display anything. Need help !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:23:34+00:00Added an answer on June 1, 2026 at 11:23 am

    Do you call the CriminalPic Servlet from a img tag’s src attribute in HTML ?
    If yes, then here is my idea.

    public class CriminalPic extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        InputStream is = null;
        OutputStream os = response.getOutputStream();
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "epolicia", "admin");
           PreparedStatement ps = con.prepareStatement("select * from CRIMINAL_PIC where CRIMINAL_ID = ?");
            String id = request.getParameter("id");
            ps.setString(1,id);
            ResultSet rs = ps.executeQuery();
            rs.next();
            Blob  b = rs.getBlob("PICTURE");
            response.setContentType("image/jpeg");
            response.setContentLength( (int) b.length());
            is = b.getBinaryStream();
            byte buf[] = new byte[(int) b.length()];
            is.read(buf);
            os.write(buf);
        }
        catch(Exception ex) {
            File file = new File(getServletContext.().getRealPath("/pics/thief.jpg"));
            FileInputStream fis = new FileInputStream(file);
            int bytes;
            while ((bytes = fis.read()) != -1) {
            os.write(bytes);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use cURL to post data to the form on this URL:
The code import cv capture = cv.CaptureFromFile(a.avi) while True: frame = cv.QueryFrame(capture) cv.ShowImage(a',frame) Shows
image.html - <img src=showImage.php?id=44/> <-- this is the code I'm trying to make work.
I need to choose image with file open dialog and then show it in
I would like to redirect all images to a showimage.php, using htaccess But if
var currentImage; var currentIndex = 0; function showImage(index){ if(index < $('#backimg img').length){ var indexImage
I want to show image in a crystal report. Scenario is something like this.
I have a code like <a href='javascript:showImage()'><img src='/public/visit_images/img1.jpg' width=100 height=100></img></a> <div class='orig_image' style=position:absolute; width:200px;
This is written in my viewDidLoad method NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *op
I have jQuery code like this workig fine in FF, but totally fails in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.