tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: Read image from database
Date Wed, 11 Apr 2007 18:37:47 GMT
Vikram Reddy wrote:
> I think this should work :
> 
> 
>            InputStream input = null;
>           BufferedInputStream stream = null;
>              BLOB blob = null;
>              PrintWriter output = response.getWriter();
> 
>            if (res.next()) {
>                              blob = ( (OracleResultSet)
> rs).getBLOB("COLUMN_NAME");
>                                input = blob.getBinaryStream();
> 
>                               stream = new BufferedInputStream(input);
>                               int length = -1;
>                               while ((length = stream.read()) != -1) {
>                               output.write(length);
>                               }
>    }
>     /* flush the contents to the output */
>      output.flush();

That's pretty close to the approach that Don posted earlier. Couple of 
comments about the code:

The standard ResultSet supports both getBlob(int i) and getBlob(String 
colName). The standard Blob supports getBinaryStream(), as well as 
getBytes(long pos, int length). I don't see a need to use Oracle-specific APIs.

Not to be picky, but why would you assign the result of 
BufferedInputStream.read() to a var called "length"? It's just the next 
byte of data.

Just noticed that you're also reading from an InputStream and writing to a 
Writer. I'd recommend using ServletResponse.getOutputStream() instead.

> On 4/11/07, Zilberstein Yuval <YUVALZI@pelephone.co.il> wrote:
> 
>>
>> Hello,
>> Can anyone tell me how do I read an image from a Blob field in the
>> database?
>>
>> TX
>> YuvalZ

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message