//Aqui eu leio a imagem code2.gif do Banco de Dados e tento
//criar uma arquivo retorno.gif igual a imagem original
import java.io.*;
import java.util.*;
import java.sql.*;

public class BlobSelect {
  Connection conn;
  PreparedStatement pstmt;
  ResultSet rs;

  public BlobSelect() throws SQLException{
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection ("jdbc:oracle:thin:@192.168.100.5:1521:quiz","clube", "clube000");
    pstmt = conn.prepareStatement("");
  }

  public void sendToDB(){
    String pathname = "/tmp/";
    String name = "code2.gif";
    FileOutputStream out = null;

    try{
      pstmt = conn.prepareStatement("select data from media where name='" + name + "'");
      rs = pstmt.executeQuery();
      if (rs.next()){
        out = new FileOutputStream("/tmp/retorno.gif");
	byte[] b = rs.getBytes(1);
        out.write(b);
        System.out.println("Recuperei " + b.length + " bytes!");
      }//de if
    } //de try
    catch (Exception e) {
      e.printStackTrace();
    }
  }//de sendToDB

  public static void main(String[] args){
    try{
      BlobSelect w = new BlobSelect();
      w.sendToDB();
    }    catch(Exception e){      e.printStackTrace();    }
  }//de main
}//de BlobSelect







