//Aqui eu leio a imagem "/tmp/code2.gif"
//e a insiro no Banco de Dados
import java.io.*;
import java.util.*;
import java.sql.*;

public class BlobInsert {
  Connection conn;

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

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

    try{
        File pictFile = new File(pathname+name);
	int pictFileSize = (int) pictFile.length();
	in = new FileInputStream(pictFile);
        PreparedStatement pstmt = conn.prepareStatement("insert into media values ('"+name+"',?)");
	pstmt.setBinaryStream(1,in,pictFileSize);
	pstmt.executeUpdate();
        System.out.println("Inseri " + pictFileSize + " bytes!");
    } //de try
    catch (Exception e) {
      e.printStackTrace();
    }
  }//de sendToDB

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








