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 8618073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:01:15+00:00 2026-06-12T06:01:15+00:00

I am creating web application where I am storing image in MYSQL DB as

  • 0

I am creating web application where I am storing image in MYSQL DB as MEDIUMBLOB and displaying them on the browser.

PreparedStatement psmt = con.prepareStatement("SELECT pdfImage FROM pdfInfo WHERE pdfinfoid=?");
psmt.setString(1, what);
ResultSet rs1 = psmt.executeQuery();

while (rs1.next()) {
    System.out.println("inside rs1.mext");
    String imgLen = rs1.getString(1);
    System.out.println(imgLen.length());
    int len = imgLen.length();
    System.out.println("length inside == " + len);
    byte[] rb = new byte[len];
    InputStream readImg = rs1.getBinaryStream(1);
    InputStream inputStream = readImg;
    int index = readImg.read(rb, 0, len);
    System.out.println("index----------------" + index);
    response.reset();
    response.setHeader("Content-Length", String.valueOf(len));
    response.setHeader("Content-disposition", "inline;filename=/file.png");
    response.setContentType("image/png");
    response.getOutputStream().write(rb, 0, len);
    response.getOutputStream().flush();
}

The problem is that I am able to see images locally and when I take project live. The problem is with one image only.

Output for the sout statements are as below.

INFO: inside rs1.mext
INFO: 5942414
INFO: length inside == 5942414
INFO: index----------------5942414
INFO: leng here is 5942414

When this info is on localhost, I can view the image, however when I take this project online, I am not able to view the image.

Do I need to set any parameter anywhere so that I can see the image.

Other sout statements are as below for which I can see images.

INFO: inside rs1.mext
INFO: 204999
INFO: length inside == 204999
INFO: index----------------204999
INFO: leng here is 204999



INFO: inside rs1.mext
INFO: 515274
INFO: length inside == 515274
INFO: index----------------515274
INFO: leng here is 515274
  • 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-12T06:01:16+00:00Added an answer on June 12, 2026 at 6:01 am

    Your problem may be the line:

    int index = readImg.read(rb, 0, len);
    

    The read method is not guaranteed to read all the data you are requesting.

    http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#read(byte%5B%5D,%20int,%20int)

    “Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a multi-user/company web application in PHP & MySQL. I'm interested to know
I creating a web application using JSF,Hibernate,Spring. I have added a filter for checking
I'm creating a web application using spring mvc. I have started to incorporate the
I am creating a web application in ASP.net/VB.NET and I have an issue with
I am creating a web application that will have many users. Each user has
I am creating a web application in Java in which I need to run
I am creating a web application with MVC3 and MEF. I am attempting to
I am creating a web application framework, in which I am providing support for
I am creating a web application which has a few management screens, where a
I am creating an web application and I at the point that i am

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.