dcsimg
get image from database
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   suzy_salim
Posted On:   Wednesday, August 15, 2001 04:59 AM

how can i get image that stored in
Ms Access database. i'm using three
elements ; jdbc,bean(servlet) and JSP

Re: get image from database

Posted By:   Roshan_Shrestha  
Posted On:   Wednesday, August 15, 2001 05:32 AM

Connection con = null;

PreparedStatement stmt = null;


try

{

 // get connection

 String queryString= "SELECT IMAGE FROM TABLE_NAME WHERE IMAGENAME=?

 stmt =
 con.prepareStatement(queryString);

 stmt.setString (1, imageName);


 stmt.executeQuery();

 ResultSet rs = stmt.getResultSet();

 if( rs.next() )
 {

  // set mime type

  response.setContentType( "image/gif");

  InputStream is =
  rs.getBinaryStream(1 );

  OutputStream os =
  response.getOutputStream();

  byte b[] = new byte[16384];

  int numBytes;

  while( ( numBytes=is.read( b ) )!=-1 )

  {

  os.write( b, 0, numBytes);

  os.flush();

  }


  is.close();

  os.close();

 }

catch( IOException e)

{

}

finally

{

 // free statement and connection

}
About | Sitemap | Contact