import  java.io.*;  
import  java.sql.*;  public  class  GetImage  
{  
public  static  void  main(String  args[])  
{  

String  username;  
String  password;  
String  url;  
String  dropString;  
String  createString;  

username  =  "root";  
password  =  "root";   
        url  =  "jdbc:mysql://localhost/dangan";   try  
{  
        Class.forName("org.gjt.mm.mysql.Driver");  
} catch(java.lang.ClassNotFoundException  e)  
{  
System.err.print("ClassNotFoundException:  ");  
System.err.println(e.getMessage());  
}  

try  
{  
Connection  con;  
Statement  stmt;  
InputStream in=null;
con  =  DriverManager.getConnection(url,  username,  password);  
System.out.println  ("Ok,  connection  to  the  DB  worked.  Let's  see  if  we  can  insert  something:");  
Statement stat=con.createStatement();
String sql="select size from image";
ResultSet rs=stat.executeQuery(sql);
while(rs.next())
{
in=rs.getBinaryStream("size");
}
FileOutputStream fileout=new FileOutputStream(new File("c:\\22.jpg"));
int size=in.available();
byte[] by=new byte[size];
in.read(by);
fileout.write(by,0,size);
fileout.close();
in.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}