• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

how can we store image and get it back from SQL Server

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am facing problem in storing and retrieve image to and from sql server so if you know the code than please paste it
thanx for taking time for reading this question
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not have code available but I can walk you through to process.
To Insert an image into the db, read the file into a byte[].
Create a PreparedStatement with the appropriate SQL.
Call the preparedstatement setBinaryStream(int pos, InputStream is, int length)
Use the ByteArrayInputStream in place of the InputStream as this will take the byte[] in the constructor.
Execute the prepared statement.
To read the image back from the db, run an SQL query and obtain a resultset.
Call the resultset getBinaryStream(int pos) method to get an InputStream.
Use this stream to read the bytes back from the db and re assemble them in an image file.
This method expects to read to and from a file. The ByteArrayInputStream is trick to make the db think it came from a file.
Sun Certified Programmer for the Java2 Platform
Destiny's powerful hand has made the bed of my future. And this tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic