Hang on, 8i(as i saw in the other post), you'll need to use other 3l language like java/c etc... try this jdbc code for instance....
this insert stores a reference to your operating system file that's in your bfile dir...
and this reads the contents in your bfile and stores it into another os file,(all via the database) like you asked.. but test it first!!Code:// variables Statement stmt = null; ResultSet resSet = null; try { // create a statement stmt = dbConn.createStatement(); // insert new row stmt.execute(" INSERT INTO lobsamp " + " (id" + " ,name" + " ,bfile_col" + " )" + " SELECT lobsamp_seq.nextval" + " , '" + strFile + "'" + " , bfilename('BFILE_DIR','" + strFile + "')" + " FROM dual"); } catch (Exception ex) { System.err.println("Error loading BFILE data: " + ex.toString()); try { dbConn.rollback(); } catch (Exception e) {} } finally { // close the statement try { stmt.close(); } catch (Exception e) {} }
Code:// variables String strStatement = null; Statement stmt = null; ResultSet resSet = null; BFILE bFile = null; String strFileName = null; String strDirectory = null; InputStream bfileInputStream = null; OutputStream sampleFileStream = null; try { // select the bfile locator from the database strStatement = " SELECT name" + " , bfile_col" + " FROM lobsamp" + " WHERE id = " + lngId; stmt = dbConn.createStatement(); resSet = stmt.executeQuery(strStatement); if (resSet.next()) { strFileName = resSet.getString("name"); // get the locator bFile = ((OracleResultSet)resSet).getBFILE("bfile_col"); } // Save as dialog box to get directory and file name to save as FileDialog selFile = new FileDialog(mainFrame, "Save as", FileDialog.SAVE); selFile.setFile(strFileName); selFile.show(); strDirectory = selFile.getDirectory(); strFileName = selFile.getFile(); // show directory alias System.out.println("... directory alias: " + bLocator.getDirAlias() + " ..."); // show file name System.out.println("... file name: " + bLocator.getName() + " ..."); // check if file exists System.out.println("... does the file exist: " + bLocator.fileExists() + " ..."); // show file length System.out.println("... file length = " + bLocator.length() + " ..."); // open the file and get the stream bLocator.openFile(); bfileInputStream = bLocator.getBinaryStream(); // open the file to write to File file2Save = new File(strDirectory + strFile); sampleFileStream = new FileOutputStream(file2Save); // define the buffer size int intBufferSize = BFILEBUFSIZE*NUMCHUNKS; // buffer to hold chunks of data to read from the BFILE byte[] bBuffer = new byte[intBufferSize]; // read a chunk of data from the BFILE, and write // the chunk to the file. int intBytesRead = 0; while ((intBytesRead = bfileInputStream.read(bBuffer)) != -1) { sampleFileStream.write(bBuffer,0,intBytesRead); } } catch (Exception ex) { System.err.println("Saving BFILE data: " + ex.toString()); } finally { // close input stream, output stream, bfile and statement if (sampleFileStream != null) { try { sampleFileStream.close(); } catch (Exception e) { System.err.println("Could not close file output stream!"); } } if (bfileInputStream != null) { try { bfileInputStream.close(); } catch (Exception e) { System.err.println("Could not close bfile input stream!"); } } try { bLocator.closeFile(); } catch (Exception e) { System.err.println("Could not close bfile file!"); } try { stmt.close(); } catch (Exception e) { System.err.println("Could not close the statement!"); } }
Try it out and let us know here...





Reply With Quote