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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:25:28+00:00 2026-06-02T19:25:28+00:00

I have saved icon size images in a mysql database in bytes, now, what

  • 0

I have saved icon size images in a mysql database in bytes, now, what I need to do is retrieve those file bytes from the database and show those images in a swing application, I have a method which gets the bytes from the database and convert it back to a file but I have to write that file in to the disk

this is my method,

public void downloadFile(int FamerId) throws Exception {
  String sql = "SELECT * FROM images WHERE famer_id=?";
  Connection con = JDBCConnectionPool.getInstance().checkOut();
  PreparedStatement ps = con.prepareStatement(sql);        
  ps.setInt(1, FamerId);
  ResultSet resultSet = ps.executeQuery();

  int count = 0;

  while (resultSet.next()) {
    ByteArrayInputStream bais;
    ObjectInputStream inputStream;

    bais = new ByteArrayInputStream(resultSet.getBytes("image"));
    inputStream = new ObjectInputStream(bais);
    SaveFile sf = (SaveFile) inputStream.readObject();
    FileOutputStream out = new FileOutputStream("fileLocation/" + resultSet.getString("image_name"));
    byte[] bytes = sf.getArray();

    int c = 0;
    while (c < bytes.length) {
      out.write(bytes[c]);
      c++;
    }

    out.close();
    inputStream.close();
    bais.close();            
    JDBCConnectionPool.getInstance().checkOut();
  }
}

but this method doesn’t give what I need, please assist me.

  • 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-02T19:25:29+00:00Added an answer on June 2, 2026 at 7:25 pm

    You can read images directly from byte streams with the ImageIO class. Assuming of course that you have previously written the image data in a compatible format. Which is hard to say given the fact that in your code you use an intermediary object input stream when reading your byte data. Here’s an example of how you can create an image directly from the database without using intermediary files:

    bais = new ByteArrayInputStream(resultSet.getBytes("image"));
    final BufferedImage image = ImageIO.read(bais);
    // pass the image to your Swing layer to be rendered.
    

    And an example of how you would have written the data to the database, in order to be able to use this code:

    final ByteArrayOutputStream baos = new ByteArrayOutputStream(64000);
    ImageIO.write(image, "PNG", baos);
    final byte[] data = baos.toByteArray();
    // write data to database
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have saved a dataset in the sql database in an xml column using
I have a kmz file that I have saved as kml to use in
I have some URLs in an Excel file which I have saved as a
using fconnect user have authenticated and i have saved their userid to my database.
Suppose, I have saved some permissions in the database by using this code: RoleRepository
I have been trying to make a updateable grid.Which means i show an icon
i have created a icon in photoshop and its a png file i have
I have a code that reads an HTML file from my local web server
I have an application that imports data from a pickled file. It works just
I have saved a bunch of CGContextRefs and I want to draw all of

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.