How to store a Word file inside a database using the BLOB ?.


Web tier: servlets, JSP, Web frameworks: How to store a Word file inside a database using the BLOB ?.

  1. Hi Friends,

    How do i store a Micosoft Word document inside a database using BLOB?.

    Database: IBM DB2 UDB 7.1
    Column Type: BLOB

    The requirement is that the user selects word file in the browser. Once he clicks the Submit, the file has to be stored in the database. I required to write a servlet to handle this.

  2. You need to upload the file via a form using enctype="multipart/form-data". Your servlet can then grab the word doc as a byte[] or binary stream and insert it into your blob field.

    Struts really makes the upload part easy...if your not using Struts, it may be worth it just for this one feature. There are other api's out there that handle form uploads too..struts just happens to be the one i use. If you would like more detail on doing this with struts, email me at notsew_nekia at yahoo dot com.

    Im doing the very same thing on a project now.
  3. For file uploads, you'll want to use one of the following:


    2) Jakarta Commons FileUpload

    3) Jakarta Struts 1.1

        package: org.apache.struts.upload

    The BLOB I/O can be tricky.

    Sun provides a standard Blob class: java.sql.Blob

    Note: Oracle's JDBC driver requires you to use an Oracle
    proprietary API for BLOB I/O.