Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/08/2007, 01:26
Avatar de elAntonie
elAntonie
 
Fecha de Ingreso: febrero-2007
Mensajes: 894
Antigüedad: 19 años, 9 meses
Puntos: 10
Re: recuperar una imagen de la Bd al jsp

Wenas

Pues un oracle.sql.BLOB.

Código PHP:
    Statement stmt = null;    
    
ResultSet rs = null;
    
oracle.sql.BLOB blob = null;
    
oracle.sql.BLOB logo = null;
    
byte [] resultado=null;
  
String query = "select logo from logos"; 

    try
    {
        
stmt = con.createStatement();    
        
rs = stmt.executeQuery(query);
        
InputStream stream = null;
        
int size = 0;
        if (
rs.next())
        {
            
blob=((OracleResultSet)rs).getBLOB(1);
            if (
null != blob)
            {
                
logo = blob;          
                
stream = logo.getBinaryStream();
                
size = (int) logo.length();
                
resultado = new byte [size];
                
stream.read(resultado);
            }
               else
               {
                      
//si no hay logo sacamos una imagen en blanco
                      
ServletContext sc = getServletContext();
                        
                      
String filename = sc.getRealPath(File.separator + "imagenes" + File.separator + "nada.jpg");
                       
File f=new File(filename);
                       
size=(int) f.length();
                       
resultado=new byte[size];
                       
stream = new BufferedInputStream(new FileInputStream(f));
                       
stream.read(resultado);
               }
        }   
    }catch (
IOException e)
    {
         
Traza.exception(this,"->obtenerLogo->IOException->"+e.getMessage());
    }
    
    catch (
SQLException e)
    {
        
Traza.exception(this,"->obtenerLogo->SQLException->"+e.getMessage());
    }
    
    return 
resultado;
}