Results 1 to 7 of 7
  1. #1
    ravee is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default image retrieval from sql server using java

    Hi,
    our clients have a sql server database in which one of the table column of image data type holds a image. The problem is, the column holds image along with some other data which they are doing by using some appendchunk method from VB. they are able to retrieve the image from the column with the help of a method called GetChunk in VB, now i have to do the same thing from java but I am not able to retrieve the image. I have tried resultset.getBytes() & getBinaryStream() by (they are giving the image size in another column) using the imgsize column, I have tried retrieving only certain no of bytes, but not able to see the image. If any body knows about this issue plz reply.......
    Following is the method they are using to retrieve the image using VB code:
    GetChunk(0, recset("imgsize") * 2)

  2. #2
    skaspersen is offline Member
    Join Date
    Jul 2008
    Posts
    31
    Rep Power
    0

    Default

    You need to access the column as a blob.

    Java Code:
       Blob blob = resultSet.getBlob("imgColumn");
       BufferedInputStream in = new
         BufferedInputStream(blob.getBinaryStream());
    Then use in as if it were a file

    HTH
    Stephen
    Last edited by skaspersen; 07-21-2008 at 01:27 PM.

  3. #3
    ravee is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default

    I have tried like this, but not working...

    Quote Originally Posted by skaspersen View Post
    You need to access the column as a blob.

    Java Code:
       Blob blob = resultSet.getBlob("imgColumn");
       BufferedInputStream in = new
         BufferedInputStream(blob.getBinaryStream());
    Then use in as if it were a file

    HTH
    Stephen

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    What, specifically, is not working?

    Are you getting the bytes and can't display them? or can't get the bytes?

    As a test, retreive the bytes and write them out to a file and try to open the file with an image viewer program

  5. #5
    ravee is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default

    I am able to get the bytes, but its not able to show the image...
    they are inserting the image by using some AppendChunk method in VB and as a proof they are able to get the image properly by using a method called GetChunk. From net I came to know that GetChunk returns bytes only, but when I try to get the image from java its not getting retrieved properly. Can u plz tell if there is any specific procedure to retrieve the image if it is inserted by using AppendChunk. some method like that of GetChunk in VB...

  6. #6
    skaspersen is offline Member
    Join Date
    Jul 2008
    Posts
    31
    Rep Power
    0

    Default

    What format is the image? Is it BMP?
    Java does not display a windows bitmap file, you have to write your own decoder.

    Have you written the data to a file and tried to open it from an external image viewer eg "Windows Picture and Fax Viewer" as fishtoprecords suggested?

    Is the column type on the server varchar? If so you may have this problem The getBytes function incorrectly converts the raw bytes in the varchar data type column to the lower byte of the Unicode representation in the SQL Server 2000 Driver for JDBC
    Last edited by skaspersen; 08-01-2008 at 01:57 PM.

  7. #7
    ravee is offline Member
    Join Date
    Jul 2008
    Posts
    4
    Rep Power
    0

    Default

    1. I tried viewing the file using Windows Picture and Fax Viewer, no result... :(
    2. No the column type is image.

Similar Threads

  1. Server socket - send image to client
    By Hinty in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 07:39 AM
  2. image download from server
    By willemjav in forum Java Applets
    Replies: 2
    Last Post: 04-03-2008, 10:13 PM
  3. Replies: 0
    Last Post: 03-11-2008, 02:20 PM
  4. Replies: 0
    Last Post: 01-08-2008, 05:29 PM
  5. Lucene Image REtrieval 0.5.4
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-11-2007, 03:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •