본문 바로가기

work/oracle

blob 관련

//empty_blob()이 꼭 필요..
1. insert into testtable values (1, empty_blob());
2. example)

  statement = conn.createStatement();
  resultSet = statement.executeQuery( " select * from testtable");
  if (resultSet.next()) {
    oracle.sql.BLOB blob = ((OracleResultSet)resultSet).getBLOB(1);
  }
  OutputStream outstream = blob.getBinaryOutputStream();
  ByteArrayInputStream ba = new ByteArrayInputStream(fileContent);
  int chunk = blob.getChunkSize();

byte[] buffer = new byte[chunk];
//byte[] buffer = new byte[1024*16];
int length = -1;


while (( length = ba.read(buffer)) != -1) {


outstream.write(buffer,0,length);
//outstream.flush();
}
outstream.close();
ba.close();