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

Fetching Image Data

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I would like to know how to get the image data of data-type "image" stored in Microsoft's MS Sql Server Database using which JDBC method .

I tried using getBinary() but throws an exception.

And if i am in a wrong direction then which datatype available in Microsoft's MS Sql Server Database should i use for storing images & which method can i use to access that data using JDBC??

Thanks
[ September 11, 2005: Message edited by: Bear Bibeault ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried using getBinary() but throws an exception.


Why don't you tell us what kind of exception that is? There are any number of reasons why this could fail.

I would hope that the image datatype is not something MS-specific, but just a binary representation of a common file format. What do the SqlServer docs say about the format of the image type?
 
Smitesh Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The exception is java.lang.NullPointerException.
Also if it the image data is null then is it possible that it can give this NullPointerException??

Thanks
 
Ranch Hand
Posts: 293
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to store binary data in an image column in SQL Server. Can you give an example of where the code is giving a NPE?
[ September 12, 2005: Message edited by: Dave Salter ]
 
Smitesh Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

I have found out where the problem is occuring.
Actually I have the image data which i have converted to bytes & sending it to my servlet in small chunks .Then on the servlet I am opening an input stream & writing all the data from that inputstream to ByteArrayOutputStream till read() doesn't = -1 .
Then i am converting the data written to the ByteArrayOutputStream to byteArr[] & then inserting that byte[] into the database.

Here the problem is occuriing the whole byte[] is not getting properly inserted into the database & thats why i am facing difficulty in fetching that data.

So kindly guide me how to write a byte[] into Sql Server database having datatype "image" & how to retrieve the same.

If possible provide me some code.

Thanks
 
Dave Salter
Ranch Hand
Posts: 293
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an article that explains how to serialize objects to the database. It includes sample code that should help you.

Cheers,

Dave.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic