Oracle
 sql >> Database >  >> RDS >> Oracle

come inserire un file enorme in BLOB (Oracle) senza caricare il file completo in memoria?

Per quelli là fuori...

Ecco la procedura per farlo:

stmt.execute ("INSERT INTO my_blob_table VALUES ('row1', empty_blob())");
BLOB blob;
cmd = "SELECT * FROM my_blob_table WHERE X='row1' FOR UPDATE";
ResultSet rset = stmt.executeQuery(cmd);
rset.next();
BLOB blob = ((OracleResultSet)rset).getBLOB(2);
File binaryFile = new File("john.gif");
System.out.println("john.gif length = " + binaryFile.length());
FileInputStream instream = new FileInputStream(binaryFile);
OutputStream outstream = blob.setBinaryStream(1L);
int size = blob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;

Fonte:http://docs.oracle.com /cd/B19306_01/java.102/b14355/oralob.htm#CHDFHHHG