Error en la recuperacion de archivos BLOB de la BD Oracle

"Yvan Huarac" <yhuarac-jYxKF9gjiIqmoKa8/[email protected]>
Newsgroups gmane.comp.java.javaspain
Message-ID <[email protected]>
Hola a todos.

Una ayuda con el siguiente código urgente:

El código lee archivos de la base de datos y las ingresa a un archivo, lo que sucede es que este genera un error, me parece que es debido a un tema de tamaño de archivo.

El error que genera es el sgte:

Genera una cantidad de archivos y de un momento a otro case lanzando la excepción descrita
Help. please.
Inicializando programa ...

Conexion correcta

java.lang.NullPointerException

at yhuarac.Oracle.Blob.RecuperadorBLOB.RecuperarBLOB(Main.java:96)

at yhuarac.Oracle.Blob.Main.main(Main.java:40)

Exception in thread "main" 

CODIGO ADJUNTO


--------------------------------------------------------------------------------

  /*
  * Main.java
  *
  * Created on 20 de agosto de 2008, 22:45
  *

  */
  package yhuarac.Oracle.Blob;
  import java.io.FileOutputStream;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.File;

  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.sql.ResultSet;
  import java.sql.Blob;
  import oracle.jdbc.driver.OracleConnection;
  import oracle.jdbc.driver.OracleDriver;
  /**
  *
  * @author yhuarac
  */
  public class Main { 
  public static void main(String[] args) { 
  System.out.println("Inicializando programa ...");
  Connection conn = null;
  GestorDeConexiones gc = null;
  try{ 
  gc = new GestorDeConexiones("digita", "digita");
  conn = gc.getConnection();
  String path = "c:\\javaout";
  Statement stmt = conn.createStatement();
  ResultSet rset = 
  stmt.executeQuery("select cod_personal||nro_orden CO_ARCHIVO from archivos where rownum<10000");
  //cod_personal||nro_orden='00006515880002b'
  while (rset.next())
  RecuperadorBLOB.RecuperarBLOB(conn,rset.getString(1),path);
  //RecuperadorBLOB.RecuperarBLOB(conn,"000002",path);
  //RecuperadorBLOB.RecuperarBLOB(conn,"000003",path); 
  stmt.close(); 
  }
  catch (SQLException sqle) {
  System.out.println
  ("Error de acceso a BD:" + sqle.getMessage()); 
  sqle.printStackTrace();
  }
  catch (IOException ioe){
  System.out.println
  ("Error de acceso a disco:" + ioe.getMessage());
  ioe.printStackTrace();
  }

  try{
  if (gc != null && conn != null)
  gc.closeConnection();
  }
  catch (SQLException sqle)
  {
  System.out.println
  ("Error de acceso a BD:" + sqle.getMessage()); 
  sqle.printStackTrace();
  conn = null;
  gc = null;
  }
  System.out.println("Finalizando programa ...");
  } 
  }
  class RecuperadorBLOB
  {
  public static void RecuperarBLOB
  (Connection cn, String idBLOB, String path)
  throws SQLException, IOException
  {
  FileOutputStream fos = null;
  Statement st = null;
  ResultSet rs = null;
  String sql ="select cod_personal||nro_orden CO_ARCHIVO, " +
  " cod_personal||nro_orden NOMBRE_ARCHIVO, " + 
  " imagen BIN " +
  "from archivos " + 
  "WHERE cod_personal||nro_orden = '" + idBLOB + "' ";

  try{
  st = cn.createStatement(); 
  rs = st.executeQuery(sql);
  if (rs.next()) 
  { 
  String pathname= 
  path + "\\" + rs.getString("NOMBRE_ARCHIVO")+".gif" ;
  File file = new File(pathname);
  fos = new FileOutputStream(file); 
  Blob bin = rs.getBlob("BIN");
  InputStream inStream = bin.getBinaryStream();
  int size = (int)bin.length();
  byte[] buffer = new byte[size];
  int length = -1;
  while ((length = inStream.read(buffer)) != -1)
  {
  fos.write(buffer, 0, length); 
  } 
  }
  }
  catch (IOException ioe)
  {
  throw new IOException(ioe.getMessage());
  }
  finally 
  {
  if (fos != null)
  fos.close();
  if (rs != null)
  rs.close();
  rs = null;
  st = null; 
  } 
  }
  }

  class GestorDeConexiones
  {
  private String user;
  private String password;
  private Connection conn = null;
  private boolean conectado = false;

  public GestorDeConexiones(String usr, String pwd){
  user = usr;
  password = pwd;
  }

  public void closeConnection() throws SQLException{
  if (conectado)
  conn.close();
  }

  private void conectar() throws SQLException {

  String url; 
  DriverManager.registerDriver(new OracleDriver()); 


  // url = "jdbc:oracle:oci:@<TNS_NAME>";
  // url = "jdbc:oracle:thin:@<server>:<port=1521>:<SID>";
  // url = "jdbc:oracle:oci:@ORCL";
  url = "jdbc:oracle:thin:@192.168.69.74:1526:BDCAJA02";
  conn = DriverManager.getConnection(url,user, password);
  System.out.println("Conexion correcta"); 
  conectado = true;
  } 
  public Connection getConnection() throws SQLException
  {
  if (!conectado) 
  conectar();
  return conn;
  } 
  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.