1 Reply Latest reply: May 25, 2007 2:08 AM by 807606 RSS

    How to read file contents from database

    807606
      Can any buddy pl tell me the solution for this...i have tried like this
      try{
                     

                     sqlStr="select fm.V_ID VId,fd.V_FILE_NAME fileName,fd.V_FILE_SIZE fileSize,fd.V_FILE_CONTENTS fileContents from FILEMANAGER_MST fm,FILEMANAGER_DATA fd where fm.V_ID = fd.V_ID and fm.V_CVDPLNO= '"+jobNo+"' and fm.V_DELETEDFLAG='N' and fm.V_FOLDER_NAME='"+folder.toUpperCase()+"'AND FM.V_PRJ_NAME='ALPS'" ;

                     System.out.println(" getFileNamesDB -"+sqlStr);
                     ovPool = new ConnectionPool();
                     ovCon = ovPool.createConnection();
                     ovStat = ovCon.createStatement();
      ovRset = ovStat.executeQuery(sqlStr);
                     if(ovRset != null){
                          while(ovRset.next()) {
                          
                                    image = ((OracleResultSet) rset).getBLOB("fileContents"); // modified.
                                    
                                    blobLength = image.length();
                                    chunkSize = image.getChunkSize();
                                    binaryBuffer = new byte[chunkSize];
                               

                                    for (position = 1; position <= blobLength; position += chunkSize)
                          {


                               // Loop through while reading a chunk of data from the BLOB
                               // column using the getBytes() method. This data will be stored
                               // in a temporary buffer that will be written to disk.
                               bytesRead = image.getBytes(position, chunkSize, binaryBuffer);

                               // Now write the buffer to disk.
                               // outputFileOutputStream.write(binaryBuffer, 0, bytesRead);
                               out.write(binaryBuffer, 0, bytesRead);
                               totbytesRead += bytesRead;
                               totbytesWritten += bytesRead;
                          
                               System.out.println("5 bytes written"+totbytesWritten);
                          }

                          }
                     }
                }catch(Exception e){
                     System.out.println("Error for this Job: "+ jobNo);
                }finally {

      is tht ok ,plz guys n girls help me out thanx in advance