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());}
...