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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:00:22+00:00 2026-05-14T23:00:22+00:00

Given an object X; I want this object to have an image. The image

  • 0

Given an object X; I want this object to have an image. The image must be stored in the database. I can’t store the path, the actual image must be in the database.

My question can be answered by answering the following subquestions:

a). What type of field should I put in the database? (e.g VARCHAR)

b) What type of object should I use for storing and manipulating the image (at an object layer)? (e.g java.awt.Image)

c) How do I create an object of the type selected (answer of question b) from the data obtained from the database?

d) How do I save an object of the type selected (answer of question b) to the database?

e) How do I draw the image on a web page?

I am using PostgreSQL, Java and it is a web application.

Thanks!

  • 1 1 Answer
  • 1 View
  • 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-05-14T23:00:23+00:00Added an answer on May 14, 2026 at 11:00 pm

    a) What type of field should I put in the database? (e.g VARCHAR)

    An image is binary data. Just use a binary field. In PostgreSQL it’s bytea.

    b) What type of object should I use for storing and manipulating the image (at an object layer)? (e.g java.awt.Image)

    Use an InputStream or byte[] to store it. The Java 2D API has classes/methods which can take/return either of those types.

    c) How do I create an object of the type selected (answer of question b) from the data obtained from the database?

    Use ResultSet#getBinaryStream() to get an InputStream of it or ResultSet#getBytes() to get a byte[] of it.

    d) How do I save an object of the type selected (answer of question b) to the database?

    Use PreparedStatement#setBinaryStream() or PreparedStatement#setBytes(). Note: if you’re new to JDBC/PreparedStatement as well, then I recommend you to get yourself through the Sun basic JDBC tutorial.

    e) How do I draw the image on a web page?

    Use a HTML <img> element whose src points to an URL matching the url-pattern of a Servlet. You can pass the image identifier as request parameter or pathinfo. Inside the Servlet you just write the obtained InputStream to the OutputStream of the response the usual Java IO way. You can find a code example in this answer I posted some time ago.


    That said, storing only raw images in a database is generally not a good idea. You should preferably also store some metadata along it, such as the content type (e.g. image/jpeg, image/gif, etc) which you after all need in the response header so that the browser knows what to do with it.

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

Sidebar

Related Questions

Given an object like this: { name: joe } I want to get the
Given an SQLConnection object how can you get a schema for a single table?
Given a FieldInfo object and an object, I need to get the actual bytes
Greetings all, As seen in the image, I have an object named O (set
How do I check if a given object is nullable in other words how
Do you generally assume that toString() on any given object has a low cost
Given an object: let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" };
Given an object on a plain white background, does anybody know if OpenCV provides
Given an object like: class M(models.Model): test = models.BooleanField() created_date = models.DateTimeField(auto_now_add=True) Given sample
What is the best way to take a given PHP object and serialize it

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.