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

  • SEARCH
  • Home
  • 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 9251669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:45:37+00:00 2026-06-18T10:45:37+00:00

How to retrieve image from mysql db and show it inside tag in HTML

  • 0

How to retrieve image from mysql db and show it inside tag in HTML and that img tag should be placed inside ? Here s my code:
It displays only the image . Its not showing any content other than image.

Thanks in advance.

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page language="java"%>
<%@ page session="true"%>
<%
  try{
   //PrintWriter out=response.getWriter();

  out.println("Retrieve Image Example!");
  String driverName = "com.mysql.jdbc.Driver";
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "db";
  String userName = "root";
  String password = "root";
  Connection con = null;
  Class.forName(driverName);
  con = DriverManager.getConnection(url+dbName,userName,password);
  Statement st = con.createStatement();

 %>
  <table border='1'>
 <tr>
 <td>Name:</td><td>
 </td>My Name</td>
 </tr>
 <tr>
 <td>Image:</td>
 <td width=10px;>
 <%
 PreparedStatement pre1 = con.prepareStatement("select * from image where id="+8);
 ResultSet rs1=pre1.executeQuery();
 while(rs1.next())   
 {byte[] bytearray1 = new byte[4096];  
              int size1=0;  
             InputStream sImage1;  
               sImage1 = rs1.getBinaryStream(2);  
               response.reset();  
              response.setContentType("image/jpeg");  
              response.addHeader("Content-Disposition","filename=logo.jpg");  
              while((size1=sImage1.read(bytearray1))!= -1 )  
                {  
                  response.getOutputStream().write(bytearray1,0,size1);  
                }  
              response.flushBuffer(); 
              sImage1.close();  
              rs1.close();  
           }


    out.println("Retrieved Successfully!");
  pre.close();
  con.close();  
  }
  catch (Exception e){
  out.println(e.getMessage());
  }
%>
</td></tr>
 </table>
</body>
  </html>
  • 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-18T10:45:38+00:00Added an answer on June 18, 2026 at 10:45 am

    Images are loaded as separate requests to the request that loaded the html. As such you need to:

    • establish a URL encoding scheme that you use when specifying the src of the img element.
    • map a servlet (or similar) to that URL. The servlet loads the image based on the parameters of the URL returning that image in its response.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my php that retrieves image from mysql database. I want to resize
Here is the code I am using to try and retrieve an image from
how to retrieve image from mysql database using java servlet and show it in
I'd like to retrieve the image source within the below HTML code block, but
My problem is rather straight-forward: Retrieve an image from a MySQL database (currently stored
Given a bunch of images .gif which I retrieve from mySQL, I need to
Im new to droid programming and i got a simple retrieve image from url
How can I save and retrieve an image from a SQL Server database in
I want to be able to retrieve a remote image from a webserver, resample
I successfully stored image files in MongoDB using PHP, when i retrieve images from

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.