• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to save image to mysql?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,i use mysql database, and i want to save an image to the database using JDBC.Should i set the data type as blob? i know getting the image from the database use ResultSet.getBinaryStream(),but i don't know how to save it to the database.who can tell what to do?
please help!
thanks you!!!
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yub-
This question is asked many times in this forum. I'd recommend you typing "image" in the search facility, you'll get good results.
 
yub huang
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Andres Gonzalez!!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On a side note, it is my opinion that saving images in a database is not the best idea unless that is your only option. I will typically create an entry in the database as to a location on the hard drive of the image. You will maintain better performance on your Tables if you do it this way.
 
yub huang
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,Gregg Bolinger,why do you think saving images in a database was not the best idea? if i have 10,000 images,and some images files name were the same, can you tell me what you will do?
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good file system alternative would not use the true filename as the filename on the file system. It would use a unique ID as the filename on the hard-drive, and store the real filename in a table... EX - table name "IMAGES" columns "ID" and "FILENAME".
However, this is only good when the image only needs to be read by code residing on the server. If you are writing client/server with swing or something - it woun't be able to use it as a file. You'd have to setup shares, or some type of stream to the client. If this is the case, I'd store it in the DB.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic