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

Drew B
  • 465
  • 3
  • 6
  • 18
  • I cant find anything on how to save a picture that a USER inputs, only how to save hard-coded images – Drew B Mar 25 '13 at 21:45
  • 1
    Will this help [How to upload an image and save it in database?](http://stackoverflow.com/questions/7033676/how-to-upload-an-image-and-save-it-in-database) – Smit Mar 25 '13 at 21:47
  • use html tag 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) – user2147970 Mar 25 '13 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! – Drew B Mar 25 '13 at 21:50
  • http://www.java2s.com/Code/Java/Database-SQL-JDBC/DemoPreparedStatementSetBinaryStream.htm – 1ac0 Mar 25 '13 at 21:51

2 Answers2

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.

user2147970
  • 412
  • 2
  • 7
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.

Joni
  • 108,737
  • 14
  • 143
  • 193