Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use getBinaryOutputStream()  RSS feed

 
Maheshwari J
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to use getBinaryOutputStream() to retrieve gif file from oracle and display that gif file in the browser.
will any one help me.
I have written this coding. but i am not able to display the gif file in the browser.
sample code:
-----------
java.sql.ResultSet rset = stmt.executeQuery ("select picture from test1 where name='test2' for update");
BLOB blob=null;
int count=0;
while(rset.next ())
{
count++;
blob=((oracle.jdbc.driver.OracleResultSet)rset).getBLOB(1);
out.println(blob.length());
Object obj;
OutputStream ostream = blob.getBinaryOutputStream ();
java.io.ObjectOutputStream objs =new java.io.ObjectOutputStream(ostream);
objs.writeObject(obj);
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By using an ObjectOutputStream you are serializing a Java object out - not the same as writing a byte array representing the gif image. You also appear to be writing to the blob, not to the servlet response.
Seems to me you should read a byte array from Oracle, use the array size to set the response Content-Length then write it to the response output stream. Be sure to also set the Content-Type.
Bill

------------------
author of:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!