Diaplay  Word file stored in blob into a browser using JSP

Dear All
I have files stored in oracle table in a blob field.I store the files using forms 10g and webutil. I can upload the files and display them successfully in forms, however when i use JSP to retrieve the files and display them in Internet Explorer, I'm able to display the pdf files, bmp , jpg and video but I'm getting junk characters when I try displaying (word , excel , access or powerpoint files which might contain arabic Characters )
the code I use to display the files is as follows :
<%
try
Connection conn = null;
String username=session.getAttribute("username").toString().toUpperCase();
String password=session.getAttribute("password").toString().toUpperCase();
String ip = "*****************";
String sid = "***************";
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@"+ip+":1521:"+sid,username,password);
String par = request.getParameter("LETTER");
String par1 = request.getParameter("SERIAL");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from TableName where PK1 like '"+par+"'"+" and PK2 like '"+par1+"'" );
if (rs.next())
Blob pic = null;
byte[] blobBytesArray = null;
OutputStream stream = response.getOutputStream();
pic = rs.getBlob("BLOBFIELD");
int len = new Integer( new Long( pic.length()).toString() ).intValue();
blobBytesArray = pic.getBytes(1,len);
if (blobBytesArray != null)
if (blobBytesArray.length > 0 )
stream.write(blobBytesArray) ;
catch(Exception e)
System.out.println("Exception: " + e.getMessage() + "<BR>");
%>
can you please guide me of how to display other file types.
Best Regards.

Hello,
Ideally when you store the document put the content-type in a column and set the content type in your JSP. This will indicate to the browser what is the type of file and you should not have any issue with any type.
Regards
Tugdual Grall

Similar Messages

  • Displaying a word file stored as BLOB in the database

    Post Author: Sathish K Sekar
    CA Forum: WebIntelligence Reporting
    Hi,
    Is it possible for us to display a word file which is stored as a BLOB object in  our database.
    We are using BO XIR2.
    Thanks in advance
    Sathish

    Post Author: InfluentialSoftware
    CA Forum: WebIntelligence Reporting
    Sathish - is this query specific to wanting to display a Word file or does it relate to how to display any BLOB objects in the database via Infoview?Thanks,Andy 

  • RETRIEVE OF ETXT FILE STORED IN BLOB

    Hi,
    I have a question on utl file. I wrote some text in an utl file (text file) and stored it as blob in data base at back end while my team mate has to retrieve the data stored in blob in front end using java. when he retrieves, the file which i stored as blob is retrieved as html file not as text file i stored initially . when we retrieve a file stored as blob, how a blob file will be retrieved..is it depends on front end programmer or is there any format where a file stored as blob will be retrieved only on that format? Kindly give your expertise on this question

    As Billy said, the passing through correct mime type is the only reliable way. If you have already loaded tons of blobs without providing this information, you may try a small workaround to determine the right mime type for your files by emulating the file utility behaviour in the database - you have to load the /etc/mime-magic or something similar for your os into the database and then compare certain bytes of your lobs with those recorded in the mime-magic file. An example how it can be done is here
    http://articles.techrepublic.com.com/5100-9592_11-5219073.html
    You could so complete the missing information in the database without to unload your data , but you should be aware - this can not replace the need to provide right mime type information by loading into database.
    Best regards
    Maxim

  • Storing a Blob into MySql  from a JTextArea

    I'm using Java 1.4.1, MySql 4.0.12, and MyConnector/J 3.06
    I have an application with a JTextArea and I want to put the contents of the JTextArea into the database stored as a Blob Object. The only reason I'm using Blob is because varchar is limited in lenght by 255 characters.
    The problem I am having is actually creating the Blob Object. I get a null pointer exception no matter what I do.(Even when there is text in the JTextArea) Please take a look at my code and please help me out if you can.
    I'm not sure if I'm using the java Blob correctly as it cannot be instantiated and it's an interface not a class.
    Please give me any suggestions including if there is a better way to doing this without using a Blob object. Thanks in advance.
    // create a new Blob Object, must initialize to something
    Blob tempBlob = null;
    // viewOrdData.notes is the JTextArea
    if (viewOrdData.notes.getText().length() > 0) {
    // THIS IS THE LINE WHERE I GET THE NULL POINTER EXCEPTION
    // I tried initial position both 0 and 1
    tempBlob.setBytes(0,viewOrdData.notes.getText().getBytes())
    stmt.executeUpdate(
    "UPDATE WORKORDER "+
    "SET NOTES = "+tempBlob+" "+ // NOTES is of type Blob
    "WHERE WRKID = "+viewOrdData.workOrderID); // primary key

    Now, Storing a Blob into Database from a JTextArea or any text components becomes easy with the SerialBlob class( javax.sql.rowset.serial.SerialBlob - JDK 1.5).
    For eg..
    For Storing a Blob to Database
    pstmt.setBlob(1,new  SerialBlob(jtextArea.getText().getBytes()));For Retrieving a Blob to JTextArea
    SerialBlob sblob = new SerialBlob(rs.getBlob("FieldName"));
    jTextArea.setText(new String(sblob.getBytes(1, (int)sblob.length())));Hope this serves this problem well.
    Regards,
    R.Amirdha Gopal.

  • How to make a Word for Mac 2008 doc into a PDF using Acrobat Macintosh

    Any ideas how to turn a Word for Mac 2008 document into a PDF using Acrobat Pro?
    Thank you if you can help.

    In Word  2008 for Mac:
    go to Save As... from File menu.
    when window open click on Button show the current file type.
    when thi menu drops down you will see the following
    Choose PDF
    save.
    Then open up in Acrobat.

  • Problem with inserting two BLOBs into a table using setBinaryStream

    DBMS 9.2.0.1.0, Oracle JDBC driver 10.1.0.2.0
    The following code insert in one INSERT two BLOBs
    into two columns using PreparedStatement.setBinaryStream(). When the size of the of at least one blob exceeds
    some limit (? 2k, 4k ?), the values are swapped and
    inserted into wrong columns.
    Please, is this a problem in JDBC driver?
    ====================================================
    import java.io.ByteArrayInputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Statement;
    * Test - two BLOBs swapped problem.
    * If size of the blob is larger that some treshold, they are swapped in the database.
    public class BlobSwapTest {
    private static Connection getConnection() throws SQLException {
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch (ClassNotFoundException cnfe) {
    throw new SQLException("ClassNotFoundException: " + cnfe.getMessage());
    return DriverManager.getConnection("jdbc:oracle:thin:@//HOST:1521/DB", "USER", "PSWD");
    private static void createTable() throws SQLException {
    Connection conn = getConnection();
    Statement stmt = null;
    try {
    stmt = conn.createStatement();
    try {
    stmt.execute("DROP TABLE BlobTest2");
    } catch (SQLException e) {
    System.err.println("Table BlobTest2 was not deleted: " + e.getMessage());
    stmt.execute(
    "CREATE TABLE BlobTest2 ("
    + " pk VARCHAR(512), "
    + " blob BLOB, "
    + " blobB BLOB, "
    + " PRIMARY KEY (pk)"
    + ")"
    } finally {
    try {
    if (stmt != null) stmt.close();
    } finally {
    conn.close();
    public static void main(String[] args) throws SQLException {
    createTable();
    Connection conn = getConnection();
    PreparedStatement pstmt = null;
    try {
    conn.setAutoCommit(false);
    pstmt = conn.prepareStatement("INSERT INTO BlobTest2 VALUES (?,?,?)");
    final int size = 5000; // change the value to 500 and the test is OK
    byte[] buf = new byte[size];
    byte[] buf2 = new byte[size];
    for (int i = 0; i < size; i++) {
    buf = 66;
    buf2 = 88;
    pstmt.setString(1, "PK value");
    pstmt.setBinaryStream(2, new ByteArrayInputStream(buf), size);
    pstmt.setBinaryStream(3, new ByteArrayInputStream(buf2), size);
    pstmt.executeUpdate();
    conn.commit();
    } finally {
    if (pstmt != null) pstmt.close();
    conn.close();
    ====================================================

    See my response in the JVM forum.

  • How to open a pdf file in a web browser using jsp

    Hi,
    I have a problem opening pdf file in browser using jsp.the following is my code.Can anyone help me.Thanks
    response.setContentType("application/pdf");
    String filename="C:\\FictPos\\mypdf.pdf";
    File file = new File(filename);
    FileInputStream in = new FileInputStream(file);
    OutputStream out1=response.getOutputStream();
    byte[] buf = new byte[4096];
    int count = 0;
    while ((count = in.read(buf)) >= 0)
    out1.write(buf, 0, count);
    in.close();
    out1.close();
    }

    Don't know the problem specifically, but here are some suggestions to investigate:
    Does it show anything in the page when you view source on it?
    I would recommend using a servlet rather than a JSP page for this, if only for the fact the JSPs can insert carriage returns into places where you might not want them to. This might screw up the PDF file format?
    Try setting the a link to the jsp, right-click and "save target as..." just to see if it gets any response at all - ie bypass the browser display.
    Good luck,
    evnafets

  • Open word file, stored in database through Forms.

    Assalam-o-Alikum
    to Genius of Oracle's
    I have stored the Word file name "MY_FILE.DOC" in oracle database. Now i want to open the file through Forms, remember i am using forms 6i. is there any body who help me to open the file.
    Best Regards
    Farrukh Shaikh

    Assalam-o-Alikum
    My in tension was not to hurt any body. if it did then sorry for that.
    here is the code through which i stored the file in database
    first create the DIRECTORY CREATE DIRECTORY generic AS 'C:\temp';---- --directory path where your files will be searched for storing.
    THEN
    create table my_blob_table
    pk_name varchar2(20) primary key,
    pk_value varchar2(20),
    col_document blob
    INSERT INTO MY_BLOB_TABLE
    (PK_NAME,PK_VALUE)
    ('A','A');
    COMMIT;
    CREATE OR REPLACE PROCEDURE load_blob_from_file
    ( src_file_name IN VARCHAR2
    , table_name IN VARCHAR2
    , column_name IN VARCHAR2
    , primary_key_name IN VARCHAR2
    , primary_key_value IN VARCHAR2 ) IS
    -- Define local variables for DBMS_LOB.LOADBLOBFROMFILE procedure.
    des_blob BLOB;
    src_blob BFILE := BFILENAME('GENERIC',src_file_name);
    des_offset NUMBER := 1;
    src_offset NUMBER := 1;
    -- Define a pre-reading size.
    src_blob_size NUMBER;
    -- Define local variable for Native Dynamic SQL.
    stmt VARCHAR2(2000);
    BEGIN
    -- Opening source file is a mandatory operation.
    IF dbms_lob.fileexists(src_blob) = 1 AND NOT dbms_lob.isopen(src_blob) = 1 THEN
    src_blob_size := dbms_lob.getlength(src_blob);
    dbms_lob.open(src_blob,DBMS_LOB.LOB_READONLY);
    278 Oracle Database 11g PL/SQL Programming
    END IF;
    -- Assign dynamic string to statement.
    stmt := 'UPDATE '||table_name||' '
    || 'SET '||column_name||' = empty_blob() '
    || 'WHERE '||primary_key_name||' = '||''''||primary_key_value||''' '
    || 'RETURNING '||column_name||' INTO :locator';
    -- Run dynamic statement.
    EXECUTE IMMEDIATE stmt USING OUT des_blob;
    -- Read and write file to BLOB.
    dbms_lob.loadblobfromfile( dest_lob => des_blob
    , src_bfile => src_blob
    , amount => dbms_lob.getlength(src_blob)
    , dest_offset => des_offset
    , src_offset => src_offset );
    -- Close open source file.
    dbms_lob.close(src_blob);
    -- Commit write.
    IF src_blob_size = dbms_lob.getlength(des_blob) THEN
    $IF $$DEBUG = 1 $THEN
    dbms_output.put_line('Success!');
    $END
    COMMIT;
    ELSE
    $IF $$DEBUG = 1 $THEN
    dbms_output.put_line('Failure.');
    $END
    RAISE dbms_lob.operation_failed;
    END IF;
    END load_blob_from_file;
    after create the PROCEDURE run the procedure
    begin
    load_blob_from_file('FILE_NAME.DOC',' my_blob_table','col_document','PK_NAME','A');
    end;

  • Displaying PDF files (stored as BLOBs in Database) using Forms 6i

    Hi,
    We have PDF and Word documents stored in Database (Version 8.1.7). We are using Oracle Forms 6i as User Interface. Through Forms we could view word documents which are stored in database, using OLE container.
    But we could not view PDF files.
    It would be more helpful and valuable if I get ideas/suggestions on this.
    Thanks in advance,
    Umasankar

    Frank,
    You are correct, I totally agree with you.
    TOAD software which i suggested was not for user interface but more for testing purpose - To ensure that the documents is uploaded to BLOBS correctly.
    I am not a WEB person, but I believe sugnificant coding is required in forms6i/9i with WEB features to display the respective documents.
    If, the purpose in ONLY for testing, then TOAD can be used which requires no coding.
    -- Shailender Mehta --

  • Send files stored as blob in mysql as attachment

    Hey guys,thanks for your attention.
    Here is my question:
    Now,in my website I can upload some files into MYSQL DB,and I want to select some of these files as attachment to be sent to customer.
    I know it is very easy if the file is stored as a file in a particular directory,what i need is to get the path of the file and then use a javamail function "attachFile(path)",how can i do it when the file is stored as blob?Is there any javamail function which can be used to manipulate this process?

    Use ByteArrayDataSource, included with JavaMail 1.4 or available in
    the demo directory in earlier versions.

  • Modifying MS WORD documents stored in BLOBS. (Oracle 9i Release 9.2.0.4.0)

    I have a need to replace a string of characters in an MS Word document that is stored in a BLOB field in an Oracle 9i database.
    Background: We have a large number of MS Word documents (~50,000) and many of them contain links to other Word documents stored on various servers throughout our network. We are moving a number of these servers, thus invalidating these links. I need to be able to update these links without having to open up every one of these documents and doing it manually.
    Is it possible, using PL/SQL, to update these links in these MS Word documents that are stored in Oracle? I have currently written a quick PL/SQL routine that will find the links and provide their location within the document, but I am not sure how I can update them. The problem, as I see it, is that if the characters that I am replacing differ in length than those that are currently in the existing document, then I would have to shift the remaining bytes of the document either left or right to preserve the integrity of the document.
    Is this possible, or should I pursue another option?

    It does not have to manual, but I think you will need to use word to modify and save the documents.
    The most automated process I can think of would be to write a client program to fetch a blob, run word, and have a word macro or add in to make the edits save, and then the client program updates with the new blob.
    With that number of documents, I would probably try to fetch a bunch of blobs and have word process them all before updating them for performance reasons.
    Unfortunately I would have no clue how to do the word automation, but I wouldn't touch those blobs using pl/sql

  • Poor image quality when displaying OLE Word doc stored in BLOB

    Hello,
    I am migrating some CR Reports from VB6 to VB.NET 2008.
    The reports retrieves Word documents that is stored in BLOB column on SQL Server 2005.
    If CR.NET (same behaviour with 2005 and 2008 versions) renders the word document, the quality is really bad. Looks like an ugly moire effect. The characters below 8pt font size are hardly readable.  I have already set the option "use full color-depth" in the report options.
    If the same word doc is rendered with CR that's included in VB6, it shows a clear and sharp output - the same as displayed in word.
    Where is the difference in handling Word OLE between those two CR versions?
    Is there anything I can do to improve the quality with CR.NET?
    Regards,
    Stefan

    Hello, Stefan;
    Is this a Windows or Web application?
    Visual Basic 6.0 shipped with Crystal Reports 4.6 Visual Studio .NET 2005 ships with Crystal Reports 10.2 and VS .NET 2008 with version 10.5.
    The Crystal Reports application was rewritten in versions 5.0 and  9.0 and a great many changes were made - among them different options for including OLE Objects. See the [Note 1218374|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_erq/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes.do] for useful new functionality. I tested a report with a linked Word document and it viewed well through Visual Studio .NET 2008.
    Is it possible support for the  the Word format as a BLOB field in MS SQL Server has changed over time. What method is used to create the document as a BLOB field?
    Are you using the bundled version included with Visual Studio .NET? In the article recommending the property 'Retain Original Image Color Depth', there is a note:
    Note: This option only functions with the full version of Crystal Reports 9 or 10. This option does not function with the .NET Report Designer.
    Originally the issue was fixed but only in a full versions of Crystal Reports Developer, not in the versions bundled with Visual Studio .NET.
    I tested with a linked Word document and see some degradation when there is an image in the Word Document but not in the text itself.
    Elaine

  • Need to put contents of a file stored in FileContents into a ByteBuffer

    As the title says. Can't find anything that shows how to accomplish the goal. Have a file stored in FileContents. Need to get the file's contents into a ByteBuffer. Any ideas how I can go about doing that?
    Thanks

    That's all the spoon feeding I needed. Minus the DataInputStream, I was dead on with my final "guess" before the previous reply. DataInputStream was what i needed to complete the puzzle. Here's the final code (simple enough):
    int length = new Long(fileContents.getLength()).intValue();
    byte bytes[] = new byte[length];
    InputStream file = fileContents.getInputStream();
    DataInputStream dis = new DataInputStream(file);
    dis.readFully(bytes);
    ByteBuffer buf = ByteBuffer.wrap(bytes);
    Thanks for the spoon feeding.
    Edited by: wizzbangca on Feb 1, 2008 4:07 PM

  • How to store file content in BLOB field MySql database using java

    Hi!
    i want to store the file content in a BLOB field in MySql database using java.
    Please help me out..........
    thanx in advance...
    bye

    i stored images in db, and retrieved them. like that cant i store pdf file in db, and retrieve it back using oracle db?
    Plz help me out how to put a file in db. i need complete code. thanks in advance.

  • Display images stored in BLOB in html pages via JSP

    Hello,
    My images are stored in BLOB column of other base than portal.
    in JSP i have to display them in html pages.
    anybody have already did the same thing ?

    teggvb6,
    I believe you should be able to get it to work by doing the grants to the user specified in the DAD (i.e. the user that is logging into Oracle) rather than PUBLIC (someone else may correct me on this?).
    If you're concerned that the procedure could be called by others then I guess you could do some sanity checking within the procedure, for example checking v('APP_USER') or maybe v('SESSION') or perhaps do something clear with the REFERER http header? I haven't thought this through yet but I'm pretty sure you should be able to tie it down a bit more.

Maybe you are looking for

  • Windows no longer can see my ipod shuffle

    Plugged in my ipod shuffles into my laptop and I know get a message about the ipod being corrupted

  • Ipod is not able to snyc with laptop. ipod is locked to snyc with itunes, not able to.

    ipod is not able to snyc with laptop. ipod is locked to snyc with itunes. the ipod is not snycing with laptop.

  • 11 Updates not Installed Not Needed

    KB3021952 Kb3004361 KB3013445 KB3023562 KB3029944 KB3031432 KB2976978 KB3016074 KB3019858 KB3020338 And the Malicious Software Removal Tool Windows 8 and 8.1 for February 2015 All show up in Windows Update but won't install because it says they are N

  • Reducing size of iPhotos

    I have an individual photo in my iphoto library - I want to upload this to send to a magazine - the original image is over the 1 MB limit. How do I reduce the size of the photo?

  • Zig Zag Filter Issues

    I am  using Illustrator CS4 on a Macbook Pro with Mountain Lion...on to the issue. The first time I used the zig zag filter today I got exactly the effect I wanted: Then when edited it to to take it from 15 ridges to 14, this is what happened: I didn