• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Fetching Image Data

 
Smitesh Patel
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Dave Salter
Ranch Hand
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic