dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Advanced
Jun 10, 2008

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Read an Image from a Database Using the getBinaryStream Method

This following code shows you how to extract an image (in this example, named foto_9738533.gif) from a database using the getBinaryStream method:

try{
   sql="SELECT Foto FROM Table1 WHERE Nr_cont=9738533";
   rs=st.executeQuery(sql);
   if(rs.next())
      {
      is=rs.getBinaryStream("Foto");
      try{
         java.io.FileOutputStream out= new java.io.FileOutputStream 
            ("C:\\sgbd\\foto_9738533.gif"); 
         byte[] bf = new byte[6144]; 
         int foto_bytes=0;  
         while ((foto_bytes = is.read(bf))!=-1) 
                 { 
                 out.write(bf, 0, foto_bytes);
                 } 
         out.close();
         }catch(java.io.IOException e)
            {System.out.println(e.getMessage());}
         }
         }catch(SQLException e)
            {System.out.println(e.getMessage());}
...
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date