This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes Displaying Image from database on to the screen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Displaying Image from database on to the screen" Watch "Displaying Image from database on to the screen" New topic
Author

Displaying Image from database on to the screen

ashok pandey
Greenhorn

Joined: Jun 26, 2001
Posts: 1
Dear,
Can any one solve my problem regarding displaying image on the screen.
I have stored my image in SQL database as data type called "image" format.
I am trying to get the binary data and display on the screen using jsp. It gives me the error
"java.lang.IllegalStateException"
Here is the code that i am using
CallableStatement stmtInsert= con.prepareCall( " { call spSM_Image }");
ResultSet rs = stmtInsert.executeQuery();

response.setContentType("image/jpeg");

if (rs.next())
{
byte [] buf = rs.getBytes("photo");
ServletOutputStream op = response.getOutputStream();

for(int i=0;i<Integer.parseInt(dim_image);i++)
{
op.write(buf[i]);
}
Pls. reply if some one can help this out

ashok pandey
 
jQuery in Action, 2nd edition
 
subject: Displaying Image from database on to the screen