To keep things simple, assume that I want a database where to store different peoples name along with their photos (images - .jpg). The MySQL server to be used for this purpose is located in a remote machine. My Java program should be able both save new person info (i.e. name and image) to the server and also retreive those info and show them using a JTable.
Now, what's the best way to do it? I can think of two: 1. save the iamge in database using BLOB or 2. save the image in a directory in remote machine and a link to that file in the database.
Whatever way it is, I don't have a clue how to do it. I neither used BLOB types nor know how to and not sure what protocol to use for sending and retreiving files on a network that'll be suitable for java.
I'm a little weak on using Blobs, but you should be able to pass a byte or stream as part of a sql insert statement to create the blob. You wouldn't have to worry about any special protocols, it would all be done with the DB connetion.
Thank you all for the kind suggestions. Working with it, seeing other's code example I feel the same. Actually working with PHP and web technology made me think of the other approach.
I've settled with my approach and worked a bit with it as well. But, both inserting and retreiving seems a lot of work which I'm not comfortable with. It'd be helpful if anyone could show me some generalized steps towards acheiving the goal, so that I can logically settle it in my mind.
Storing blobs in a database leads to pain. If you are using oracle the are all sorts of rules about tables with blobs that stop you from doing things you could otherwise do (like partitioning).
On our production systems, this storing of data in BLOB types has causes us SIGNIFICANT issues as the db scales (250GB and grow, most of it BLOBs)
Store the path to the image on the file system, in the long run you will be better off!
Mousa A. Rafi
Joined: Jan 30, 2005
Nice to see different opinions. Well, if I were to build this database for a intranet or web solution that works with general HTML, HTTP protocol and probably a scripting language like PHP, I would definitely go for saving links to the files rather than BLOB. Even if the Java application was to run on the same machine where the DB server is running I would do the same. But, when it comes to building an application with Java that should work on a network and the DB server is located in a different machine then using BLOB seems easier. However maintaining the database is also an issue and hence how I can do it with links is something I'd really love to know. Thanks once again to all for your responses.