11 Replies Latest reply: Aug 19, 2008 11:56 AM by 843785 RSS

    retrieveing blob from database and writing to an output file.

    843785
      Retrieveing blob from database and writing to an output file which is an EXCEL file.
      if(res.next()) {
                          Blob blobData = res.getBlob("DOCCONTENT"); // retrieving a blob content from the database
                          String srcfileName = res.getString("filename"); //Name of the file I retrieved from the database
                          System.out.println("filename "+srcfileName);
                String fileName = "C:\\Documents and Settings\\Desktop\\blob data\\"+srcfileName; //destination filename
                          FileOutputStream os = new FileOutputStream(fileName);
                          InputStream blobStream = blobData.getBinaryStream();
                          int length = -1;
                     int size = (int)blobData.length();
                     byte[] buffer = new byte[size];
                          
                     while ((length = blobStream.read(buffer)) != -1) {               
                                         
                     os.write(buffer, 0, length);
                     os.flush();
                     }
                os.close();
                     blobStream.close();
                     }

      The output file contains data of incomaptible type and I am not able to open using Excel. What can be possibly wrong?