Noticias Weblogs Foros Wiki Código

RecorteX

» jacarui
317 usuarios y 202 recortes de código
Usuario

Contraseña
Crear cuenta
Estás viendo los recortes del usuario jacarui

RSS
Recortes: 1
Registrado: 30/8/2006
Web

Etiquetas:
java (1)
utilidades (1)
bd (1)

Leer un String de un Blob

Método para leer un String que por necesidades de tamaño se introduce en un blob. Al método se le pasa el resultSet y el nombre del campo en el que se encuentra el blob.
 
 
    public String leerBlob(ResultSet rs,String blob){
        String returndata="";
        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
        BufferedInputStream bis;
        try {
            bis = new BufferedInputStream(rs.getBinaryStream(blob));
            byte[] bindata=new byte[1024];
            int bytesread = 0;
            try {
                if ( !rs.wasNull() ) {
                    if ( (bytesread = bis.read(bindata,0,bindata.length)) != -1 ) {
                        baos.write(bindata,0,bytesread);
                        returndata= baos.toString();
                    }
                    bis.close();
                }
            } catch (IOException e) {
                System.out.println("leerBlob -- Se produjo un error en la consulta");
                System.out.println(e.getMessage());
            }
        } catch (SQLException ex) {
            System.out.println("leerBlob -- Se produjo un error en la consulta");
            System.out.println(ex.getMessage());
        }
        return returndata;
    }
 
info@recortex.com - Proyecto: Juanjo Navarro, 2006 - Diseño: Albin