• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Keeping an image in database

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mousa,
I agree that using the database is the simplest approach. Steven is correct that you can use byte[].
 
Mousa A. Rafi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do not save images in database if that is not absolutely necessary!!!
It is much better (IMHO) to save images in file system and only paths to
them in database!!

regards...
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agress with asirob

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
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
My cellmate was this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic