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;
}
RecorteX - Recortes de código útiles.
No hay comentarios:
Publicar un comentario