2

I am planning how I to write a GUI Java application that displays a form to the user to add information about themselves. One of the things I want to include is the ability for the user to add a picture to the form. Upon submission the picture and the rest of the info will then be saved to a database. Being new to java I was hoping for some instructional Links or tips as to how to accomplish this. I was thinking of setting one of my columns in my table as a 'BLOB' type and then saving them to it, but that is just a shot in the dark. I really don't know what the column type should be (byte, blob, ect...), or how to code so that the picture will be saved to my database for display later. I guess my question is how to get and save a picture to a database from a form. I am going to attempt this using eclipse, and am still unsure what I will use for the database. Sorry about any confusion, and thanks for reading!!

Drew

5
  • I cant find anything on how to save a picture that a USER inputs, only how to save hard-coded images Commented Mar 25, 2013 at 21:45
  • 1
    Will this help How to upload an image and save it in database? Commented Mar 25, 2013 at 21:47
  • use html tag <input type="file"> to get the file corresponding to the image. Then do what you want with the file on server side (minimize, change encoding, store somewhere etc) Commented Mar 25, 2013 at 21:49
  • @Smit, another good read, but it is for Java-scripting and browsers. I am just going to create a simple Java application! Commented Mar 25, 2013 at 21:50
  • java2s.com/Code/Java/Database-SQL-JDBC/… Commented Mar 25, 2013 at 21:51

2 Answers 2

1

If you really want to store your image in the database, BLOB seems to be the most adapted type for the column holding the image.

But IMHO, those types of files do not have to be stored in a database. Just store them somewhere in a directory and just keep the image names (or a generated id) in your database.

Sign up to request clarification or add additional context in comments.

Comments

0

You will need two columns in the database: a BLOB to hold the binary image data, and a text type (VARCHAR most likely) to store the file format. If you plan to use an API that automatically detects the image format you can use just the BLOB.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.