int primaryKeyId = getNextPrimaryKeyId(); PreparedStatement stmt1 = conn.prepareStatement(" insert into docTable values (?, ?, empty_blob()) "); stmt1.setInt(1, primaryKeyId ); stmt1.setString(2, getDocumentTitle()); stmt1.executeUpdate(); PreparedStatement stmt2 = conn.prepareStatement(" select doc from docTable where id = ? for update "); stmt2.setInt(1, primaryKeyId); stmt2.execute(); OracleResultSet rset = (OracleResultSet)stmt2.getResultSet(); if (rset.next()) { BLOB document = rset.getBLOB("doc"); document.trim(0); OutputStream os = document.getBinaryOutputStream(); os.write(getDocumentToBeWrittenToDb()); os.flush; os.close; }
outstream = blob.getBinaryOutputStream(); instream = new java.io.BufferedInputStream(new java.io.FileInputStream(file)); int bufferSize = blob.getChunkSize();
outstream = blob.getBinaryOutputStream();
/** * Generates an Output stream that writes to a blob, also truncating the existing blob if required.<p> * * Apparently Oracle requires some non-standard handling here.<p> * * @param res the result set where the blob is located in * @param name the name of the database column where the blob is located * @return an Output stream from a blob * @throws SQLException if something goes wring */ public static OutputStream getOutputStreamFromBlob(ResultSet res, String name) throws SQLException { // TODO: perform blob check only once and store Oracle version in a static private member // TODO: best do this during system startup / db init phase once Blob blob = res.getBlob(name); try { // jdbc standard blob.truncate(0); return blob.setBinaryStream(0L); } catch (SQLException e) { // oracle 9 & 8 (if using the same jdbc driver as provided by oracle9: ojdbc14.jar) ((oracle.sql.BLOB)blob).trim(0); return ((oracle.sql.BLOB)blob).getBinaryOutputStream(); } }
outstream = blob.getBinaryOutputStream(); int bufferSize = blob.getChunkSize(); byte[] buffer = new byte[bufferSize];
outstream = blob.getBinaryOutputStream(); int bufferSize = blob.getChunkSize(); byte[] buffer = new byte[bufferSize];