Binary file techniques

I have searched through many forums and faq's on this subject. Some say you can retrieve a blob from the database and display it on the screen some say you can't. I have been experimenting with this and I have a jsp page that is trying to do that job. I think I am nearly there but I have an error : java.sql.SQLException: [Microsoft][ODBC Driver Manager] Function sequence error. Can anyone shed some light on this situation as I believe it can be done!
I have included my code
Connection con = null;
     String shortname = null;
     String From=request.getParameter("From");
     String CusRef=request.getParameter("CusRef");
     if(From==null)
          out.println("You must enter the information -From- ");
     if(CusRef==null)
          out.println("You must enter the information -Customer Reference- ");
     try
          Class.forName(Dsn);     
          con = DriverManager.getConnection(url);
          Statement cstmt = con.createStatement();
          String sql="SELECT FileName From Table1 WHERE From='" + From + "' And CusRef = '" + CusRef + "'";
          java.sql.ResultSet rs = cstmt.getResultSet();
          while ( rs.next() )
               Blob f = rs.getBlob(1);
               InputStream in = new BufferedInputStream(f.getBinaryStream());
               //InputStream in = new FileInputStream(f);
               ServletOutputStream outs = response.getOutputStream();
               int bufferSize = 4096;
               byte[] ioBuffer = new byte[bufferSize];
               byte[] lastBuffer; // last buffer
               long counter = 0; // how many bytes we have gotten through
               long fileSize = f.length();
               System.out.println(fileSize);
               response.setHeader("Content-Disposition", "attachment;filename=" + shortname);
               response.setContentType("application/download");     
               out.clearBuffer();
               while (fileSize > (counter + bufferSize))
                    in.read(ioBuffer);
                    outs.write(ioBuffer);
               counter += bufferSize;
               // add final chunk if the fileSize does not happen to be divisible by the bufferSize
               if (fileSize > counter)
                    lastBuffer = new byte[ (int) (fileSize - counter) ];
                    in.read(lastBuffer);
                    outs.write(lastBuffer);
               outs.flush();
               outs.close();
               in.close();
     catch(Exception e)
          System.out.println(e);

Since making the changes appropriately that you have suggested I now have two errors. Here is my code as it stands and my two errors.
code
Class.forName(Dsn);     
          con = DriverManager.getConnection(url);
          Statement cstmt = con.createStatement();
          //String sql ="SELECT To From Table1 WHERE From='" + From + "' And CusRef = '" + CusRef + "'";
          String sql="SELECT FileName From Table1 WHERE From='" + From + "' And CusRef = '" + CusRef + "'";
          java.sql.ResultSet rs = cstmt.getResultSet();
          //System.out.println(rs);
          long lngTime = System.currentTimeMillis();
          boolean blnTest = false;
          while((!blnTest) && (System.currentTimeMillis() < lngTime + 2000))
               blnTest = rs.next();
               while ( blnTest )
                    Blob f = rs.getBlob(1);
                    System.out.println("Test ");
                    byte[] BlobContent = null;
                    BlobContent = rs.getBytes(1);
                    InputStream in = new BufferedInputStream(BlobContent.getBinaryStream());
                    ServletOutputStream outs = response.getOutputStream();
                    int bufferSize = 4096;
                    byte[] ioBuffer = new byte[bufferSize];
                    byte[] lastBuffer; // last buffer
                    long counter = 0; // how many bytes we have gotten through
                    long fileSize=0;
                    fileSize = BlobContent.length();
                    System.out.println(fileSize);
                    response.setHeader("Content-Disposition", "attachment;filename=" + shortname);
                    response.setContentType("application/download");     
                    out.clearBuffer();
                    while (fileSize > (counter + bufferSize))
                         in.read(ioBuffer);
                         outs.write(ioBuffer);
                    counter += bufferSize;
                    // add final chunk if the fileSize does not happen to be divisible by the bufferSize
                    if (fileSize > counter)
                         lastBuffer = new byte[ (int) (fileSize - counter) ];
                         in.read(lastBuffer);
                         outs.write(lastBuffer);
                    outs.flush();
                    outs.close();
                    in.close();
     catch(Exception e)
          System.out.println(e);
and my two errors
An error occured between lines: 19 and 100 in the jsp file: /CAR/Select.jsp
Generated servlet error:
F:\Tomcat\work\localhost\_\CAR\Select$jsp.java:155: Method getBinaryStream() not found in class java.lang.Object.
                    InputStream in = new BufferedInputStream(BlobContent.getBinaryStream());
                    ^
An error occured between lines: 19 and 100 in the jsp file: /CAR/Select.jsp
Generated servlet error:
F:\Tomcat\work\localhost\_\CAR\Select$jsp.java:163: Method length() not found in class java.lang.Object.
                    fileSize = BlobContent.length();
                    ^
2 errors
******************************************************************

Similar Messages

  • Any info on CRC, checksum, or other file integity VIs for large binary files?

    Working on send rather large binary files (U16 stream to file) via internet. Would like to check for file integity via CRC or comparable checksum. Would appreciate any comments/suggestions

    Hi Brian,
    You said;
    "Would appreciate any comments/suggestions".
    You did not mention what transport mechanism you plan on using.
    As I understand ALL of the standard mechanism use CRC of some form to ensure the validity of the packet BEFORE it is ever passed up the OSI 7-Layer model.
    TCP/IP based protocols will see to it that all of the segments of a transfer are completed and in order.
    UDP on the other hand is a broadcast type protocol and does not ensure any packets are recieved.
    So,
    At the very worst you should be able to handle your "sanity checks" by simply using a sequence value that is included in your out-going message. The reciever should just have to check if the current seq value is equal to the previous +1.
    I co-developed an app that ut
    ilized this technique to transfer status messages from a RT platform to a Windows machine. The status messages in this app where concidered FYI, so the sequence counter served as a way of determining if anything was missed.
    I am insterested in others thoughts on this subject.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Siebel 8.0.0.12 Fix Pack; Unable to get the seed from binary file.

    Hello Folks,
    Can anyone throw some light into what action is required on my scenario.
    I have applied Fix Pack Siebel 8.0.0.12 on top of 8.0.0.11 SBA. After it is appled, I am facing a documented issue within the Release Notes for the 8.0.0.12 Fix Pack
    The issue is "UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12". I tried the steps given with the MR document, however, I am still having this issue.
    I am also not sure what is expected at the step of; Run the following command: seedgeneratorutil myseed.dat abcdef .
    It's asking me for a value to enter for seed at command prompt. "Enter the seed":
    what I should give here. As an assumption values,I gave SADMIN and tried to launch but still shows up the same error
    Please Assit
    Steps Details from Release Notes:
    UNABLE TO LAUNCH URL AFTER APPLYING SIEBEL 8.0.0.12
    Component: Server Infrastructure
    Subcomponent: SWSE
    Product Version: Siebel 8.0.0.12
    Base Bug ID: 11938270
    **Users are unable to launch the URL after applying the Siebel 8.0.0.12 Fix Pack.
    **Use the following workaround to address this issue:
    Navigate to the eappweb/bin directory from the command line on the SWSE installation.
    Run the following command:
    seedgeneratorutil myseed.dat abcdef
    NOTE: In the example, myseed.dat is a filename. You can give any file name you wish.
    The myseed.dat file is generated in the eappweb/bin directory.
    Edit eapps.cfg to include the following parameters under the SWE section:
    seedfile = < complete path for myseed.dat >
    Bounce the web server.
    (For Linux only) Copy libmod_swe.so from the eappweb/bin folder to the web/ohs/modules folder
    Thanks
    Kumar

    Wilson,
    Thanks for your reply.I have repeated the steps and regenerated the error messages.
    Browser
    Message:
    An error occurred while trying to process your request. This error indicates a problem with the configuration of this server and should be reported to the webmaster (along with any errors listed below). We apologize for the inconvenience
    Initialization error:
    Unable to get the seed from binary file.
    Log
    2021 2011-09-20 23:23:01 0000-00-00 00:00:00 +0530 00000000 001 003f 0001 09 ss110920_7068 7068 7852 E:\sba80\SWEApp\log\ss110920_7068.log 8.0.0.12 [20444] ENU
    ProcessPluginState     ProcessPluginStateError     1     000000024e781b9c:0     2011-09-20 23:23:01     7852: [SWSE] Unable to get the seed from binary file.
    Eapps.cfg
    [swe]
    Language = enu
    Log = errors
    LogDirectory = $(SWSERoot)\log
    ClientRootDir = $(SWSERoot)
    SessionMonitor = False
    AllowStats = true
    LogSegmentSize = 0
    LogMaxSegments = 0
    DisableNagle = False
    seedfile = E:\sba80\SWEApp\BIN\80012seed.dat
    Thanks
    Kumar

  • Report using Binary file

    Hi All , can anyone help me here ...
    I used “Write to Binary” to  write my report , at first stage this file is writing headers , including column  headings . at 2nd writing stage it is writing  data in columns.  This file can be viewed in .doc or .xls format. I have three issues
    1.         If I want to print this file from Front Panel  , what I should do?
    2.         other thing is if I stop logging and then start for another span , it starts writing from the first line instead of from last line  , because of this problem it is causing over-writing .
    3          another thing  , lets say if for 2nd or 3rd logging , I want to display sub-headings (test-1 , test-2) , how to insert , for example :
    MAIN HEADING (COMPANY NAME , REPORT TITLE )
    DATE , PRODUCT INFO , OPERATOR NAME
    COL1              COL2              COL3              COL4
    Subheading (test-1)
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Subheading (Test-2)
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Value1             Value2             Value3             Valye4
    Any help in this regard will be highly appreciated.
    Regards
    Faiyaz
    Attachments:
    report-writing-binaryfile.vi ‏68 KB
    02-display-subVI.vi ‏12 KB

    Hi Faiyaz,
    1. How Do I Print a File Programmatically From LabVIEW?
    2. Please the Programming >> File I/O >> Advanced File Functions >> Set File Position function on the block diagram after the Open/Create/Replace File function and set the from input to "end." This will append new data to the end of the file.
    3. You can simply add that information to the Format into String you are writing to the second Write to Binary file.
    Michael K.
    | Michael K | Project Manager | LabVIEW R&D | National Instruments |

  • How to open and read binary files?

    How do I open and read Binary files?

    Did you  look on The Unarchiver's web site where it has a link to older versions? http://theunarchiver.googlecode.com/files/TheUnarchiver3.2_legacy.zip
    The best thing to do is ask your friends what programs they used to produce these files, or at least what format files they are producing.  Otherwise it's like being shown a car and given a bundle of 200 keys with no idea to which one to use, or even if any of them work with that car.
    Using The Unarchiver will likely not do anything because it too will not know what format files are involved, and they may not even been in an archived format.  If they sent you a Word file without telling you (a favorite of Windows users to do  -- it drives me crazy when they could have just sent them in plain text), The Unarchiver won't open them.  If it's a picture file then using Hexedit will just show you a bunch of unintelligible stuff as shown in an earlier post, though you may see a line of text providing a hint.
    As I said earlier, often .bin may be an executable program which needs another program to actually interpret it.  That's what Java is trying to do.  Still, it may think it can execute the file, but it is highly unlikely somebody would send you an executable program (and if they did I would not trust it).  For all you know it may be a Windows virus.

  • How do i disable to pop up asking me if i want to save or cancel the binary file i am trying to download?

    everytime i download a show or movie from the internet a pop up asks me:
    "you have chosen to open xxxxxx which is a: Binary File from: httpxxxxx would you like to save this file - SAVE or CANCEL"
    this never used to happen on the older versions of firefox. it is so annoying - is there any way to turn it off?
    i am running mac os 10.5.8 and no, there is no option to click a 'don't ask me again' feature in the pop-up dialog.

    I'd first try downloading an installer from the Apple website using a different web browser:
    http://www.apple.com/quicktime/download/
    If you use Firefox instead of IE for the download (or vice versa), do you get a working installer?

  • Reading an object from a binary file

    i am writing objects into my binary file using printwriter class. i am able to write objects into the file but i am having problems reading the object from the file. is there any other way of going about it. i tried using the objectoutputstream and object input stream class. but i am getting run time errors coz of something to do with serialization
    i am storing records as a object into a binary file so that it is easy to seek my records

    Of course you have trouble reading objects after you wrote them with a PrintWriter.
    You should rather have fixed the Serialization errors: only objkects that implement Serializable correctly can be serialized.

  • DE PDP-1 binary file from Java

    Can someone here help me, please!?
    Anyone know how to convert a Java class file into a binary file that will run natively on my Digital PDP-1 computer? I just spent over $120,000 for it! Thanks.
    This resurrected thread was first posted November 25, 1960 at 8:25AM
    -------------------------------------------------------------------------

    This resurrected thread was first posted November 25,
    1960 at 8:25AMIn what time zone?

  • How can I open different binary files from BLOB column ?

    If we store some type of binary file (XLS, DOC, PDF, EML and so on, not only pictures) in BLOB column how can I show the different contents? We use designer and forms 9i with PL/SQL.
    How can I copy the files from BLOB to file in a directory or how can I pass BLOB's content to the proper application directly to open it?

    The mime type is just a string as explained above (e.g. application/pdf...). There are lot of samples here and on metalink.
    E.g. add a column mime_type varchar(30) to your blob table. Create a procedure similar to the following:
    PROCEDURE getblob
    (P_FILE IN VARCHAR2
    IS
    vblob blob;
    vmime_type myblobs.mime_type%type;
    length number;
    begin
         select document, mime_type into vblob,vmime_type from myblobs where docname = p_file;
         length := dbms_lob.getlength(vblob);
         if length = 0 or vblob is null then
         htp.p('Document not available yet.');
         else
         owa_util.mime_header(vmime_type);
         htp.p('Content-Length: ' || dbms_lob.getlength(vblob));
         owa_util.http_header_close;
         wpg_docload.download_file(vblob);                
         end if;
    exception
         when others then
         htp.p(sqlerrm);
    END;
    Create a DAD on your application server (refer to documentation on how to create a DAD).
    Display the blob from forms (e.g. on a when-button-pressed trigger):
    web.show_document('http://myserver:port/DAD/getblob?p_file=myfilename','_blank');
    For storing blobs in a directory on your db server take a look at the dbms_lob package.
    For storing blobs in a directory on your app server take a look at WebUtil available on OTN.
    HTH
    Gerald Krieger

  • How do you open multiple binary files and plot them all on the same graph?

    I have three different binary files and I want to plot all 3 of them onto a graph.
    I am familiar with opening and reading a single binary file. (Thanks to the help examples!) 
    But to do multiple numbers at the same time?  I was thinking of putting 3 different 'reading from binary file' blocks with the rest of the 'prompts', 'data type', etc.. and then connecting them on the same wire.
    However, I got into a mess already when I tried to read one .bin file to dynamic data type --> spectral measurements --> graph waveform.  The error was Not enough memory to complete this operation...  Why is that?  That didnt happen in the help example "Read Binary File.vi"...  Has it got something to do with the dynamic data type?
    Thank you for your time.
    Jud~

    Have a look at the image below and attached VI.  Simply enter the different paths into the PathArray control.
    R
    Message Edited by JoeLabView on 07-30-2008 09:59 PM
    Attachments:
    multipleBinary2Graph.vi ‏18 KB
    multipleBinary.PNG ‏5 KB

  • How can I convert the binary file content to XML message

    Dear friends,
    I poll the binary file from a ftp server but the payload only includes the binary content, no XML structure in the payload, I hope to convert the binary content to a element node within the XML structure, how can I do that? via content conversion?
    Thanks and regards,
    Bean

    Read the binary file stream using java I/O standard functions and convert the read stream to Base64 format. Now map this content to one of the field in target XML structure.
    You need a java mapping for this.
    what is your target system?
    Thanks,
    Gujjeti.
    Hi Gujjeti,
    Thanks a lot for your kind help, my target system is R/3.
    Can I achieve that with a UDF or a simple way?
    Regards,
    Bean

  • Deleting a single element from a binary file

    I am working on a server application that must keep track of the messages that have been sent but not responded to.  After I send a message, I append it to an array cycling through an uninitialized shift register and I write it to the end of a binary file.  When I receive a response to a message, which was probably but not necessarily the first message sent, I delete that message from the array and the file.  This allows me to look up entries quickly but also to maintain a permanent record of what messages have been sent and not responded to.
    Basically, I need an intelligent way to make a file, or any other permanent storage medium, act effectively like a queue.  The problem with the current implementation is that when I delete one variable-sized entry from the file, I need to move all subsequent entries, which are usually all of the other entries in the file, forward in memory to take its place.  Is there a way to get around recopying the majority of the file or to implement this entire thing more intelligently?

    You can organize your datafile as a list. For example In this list any record consists of a fixed size data field and referencies (file position f.e.) to the next record and  to the previous record. You can then rewrite the record-have-to-be-deleted with new one, or you can "delete" this record modifiyng the referencies of the "previous" and the "next" records. When you will add a new record you can write one at this "free" place.
    The other way is to manage two files. The first one contains your data record by record. The second one contains the numbers of the records and the corresponding datafile positions or record counter. This second file can be very small and easy-to-manage. It can represent the only record's queue position in the datafile. You can rewrite your records, mark them as deleted without moving large portions of data.
    You can setup the datafile capacity in "number of records" term.
    Additionally it is possible to use the records with variable length but it will be much more dificult. 
    Best regards, Evgeny. 

  • Can I get a list of all binary files and what they do?

    I'm a newbie to Oracle. Needless to say I'm blindly muddling my way through the experiance of installations/setup and managing my first database. I realize that there is a three tier system and for my system all three of the tiers are on the same pc! In short I need help with what executables do what. I've tried going through Linux howto's, online docs, and even bought a book on the subject but the book seems to stroke the benifits of using Oracle instead of actually telling me how to use Oracle. I'm using Oracle8i 8.1.7 EE (enterprise edition) on Linux RH 7.0. I would like a link to a list or the actuall list of all the binary files in $OracleHOME/bin/ and what each of them do. Also important log files I should consult regularly would be most helpfull. Thanks.

    While you're at it, see if you can get a complete description of all the X$ tables.

  • Fulltext search of binary files outside of database in SQL 2012/Server 2012

    This may be more of a Windows Server 2012 question but I'm not sure.
    I have a system that holds large amounts of binary files (pdf, doc, etc.).  The files themselves are held outside the database in a folder and a SQL table holds the metadata.  I used the Indexing Service available through Windows Server 2008 to
    create a catalog called "EFCATALOG" to index the contents of the external folder, then created a linked server called MYIDXS which allowed me to query that external indexing catalog from within SQL with a query like this:
    EXEC sp_addlinkedserver MYIDXS, 'Internal App', 'MSIDXS', 'EFCATALOG'
    SELECT * FROM MYDOCS
    LEFT JOIN OPENQUERY(MYIDXS,'SELECT FILENAME FROM SCOPE() WHERE CONTAINS (''test'')') AS MYTBL
    ON MYDOC_FILE_NAME = MYTBL.[FILENAME]
    With Windows Server 2012, I'm missing the functionality to create the indexing service catalog.  I've added the Windows Search Service and see how I can configure folders for searching, but there is no naming functionality for this and I don't see how
    I can get the above query/structure to work in Windows Server 2012/SQL Server 2012 environment.  In fact, there isn't much at all online regarding the search service or the relationship back to the older versions in 2008 and before.
    Is there any way to continue this structure in 2012?  I would like to avoid recoding my application to work with a different structure.  I'm afraid that changing everything to work with the FILETABLE/FILESTREAM functionality added in SQL 2012
    will be necessary which is fine long term, but not convenient right now.
    Thanks in advance for any suggestions/help.

    Thank you Fanny Liu, based on your link the syntax has changed dramatically. I need to query SYSTEMINDEX now and the structure is very different.    It still seems that this new syntax requires creating a linked server of a different type. 
    I've tried:
    EXEC sp_addlinkedserver @server = 'TEST', @provider = 'Search.CollatorDSO.1', @datasrc = 'SYSTEMINDEX', @srvproduct = '', @provstr='Application=Windows'
    SELECT FileName FROM OPENQUERY("TEST", 'SELECT Filename FROM SYSTEMINDEX')
    Msg 7302, Level 16, State 1, Line 1
    Cannot create an instance of OLE DB provider "Search.CollatorDSO.1" for linked server "TEST".
    I've also tried using just "Search.CollatorDSO"as the provider since that is the provider name listed in management studio but basically the same error comes back.
    So I have 2 questions:
    1) Is it possible for my original process to work in Windows Server 2012 in any way (meaning that the OPENQUERY example I provided can remain relatively unchanged)?
    2) If change is necessary using this new SYSTEMINDEX and linked server combination, why is my linked server definition failing?  I'm using SQL Server 2012....Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
     Feb 10 2012 19:39:15
     Copyright (c) Microsoft Corporation
     Express Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
    Thank you.

  • How do I create a binary file using PL/SQL

    Hi
    Can you help me with writing a binary file in PL/SQL? I like to load binary data from data file, process in database then write to a new binary file.
    Thank you very much in advance.
    regrds
    Yongdong

    DBMS_LOB won't help you write a BLOB to disk.
    You need to an external procedure to do that. Eric K's java works great and he's helped me with his solution and probably about a thousand others.
    Doing a search on this forum will yield many discussions on this often regurgitated topic.

Maybe you are looking for