Looking at an object X; I want to put an image to this object, the image must be stored in the database. I can not store the path, the actual image should be in the database.
The answer to my question can answer the following subdivisions:
a). What kind of field should I put in the database? (Eg VARCHAR)
b) What type of object should I use for storing and adding an image (on the object layer)? (Like java.awt.Image)
c) How do I create an object of the selected type (answer to the object question) from the data obtained from the database?
d)
e) How to draw an image on a web page
I am using PostgreSQL, Java and it is a web application.
Thank you!
A) What type of field should be inserted in the database? (Eg VARCHAR)
One image is binary data just use a binary area in PostgreSQL.
b) What type of object should be used to store and add an image (on the object layer)? (Like java.awt.Image)
Use one or byte
to store it. In Java 2D API, those sections / methods can be included which can take / return one of those types.
c) How do I create a selected type of object from the received data? From the database,
get InputStream
to get it or get it by byte []
.
d) How can I save the object of the selected type (object's question) to the database?
Note: If you are new to JDBC /
prepared statement
, then I recommend you to get it myself.e) How do I image a web page?
An HTML
& lt; Img & gt;
element whosesrc
aurl-
. You can pass the image identifier in the form of request parameters or pathofof. Insideservlet's
patternservlet
, you type in the InputStream in the output stream of the response received by normal Java IO. You can find a code example some time ago.
He said, storing raw images in the database is not usually a good idea. You should also keep some metadata prefixed with it, such as (like
image / jpeg
,image / gif
, etc.) that knows the browser after you are required in the patience header That's what to do with it.
Comments
Post a Comment