JDBC BLOB Sample Application

JDBC BLOB Sample Application


This document describes how to use the Java DataBase Connectivity (JDBC) Binary Large Object (BLOB) sample application with the Sun Java System Web Server.

This document contains the following sections:


Overview

The JDBC BLOB sample application provides a web-based interface to an object repository in a database. Two servlets provide the client with the ability to manage the storage of files in the database, enabling the client to insert, update, delete, and fetch files. The files can be stored either as Binary Large Object (BLOB) data or as Long Binary data. The default setting is to save the file as BLOB data. To save the file as binary data, modify web.xml by changing the value for parameter useBlob from true to false.

The repository is a simple database table containing a BLOB column (or a similar data type) that holds the file data along with the file name, size, and MIME type of the stored content.

To use the JDBC BLOB application, complete the following steps:

  1. Bring up a web page with a form like the one shown in Figure 1.



    Figure 1:  Upload Form

  1. Select a file and click the Upload button.

    The UploadServlet is invoked. This servlet inserts the file as BLOB (or similiar data type) into the database. The servlet renders a page similar to the one shown in Figure 2.



    Figure 2:  Upload Result

  1. Click UpLoad Form to upload another file, or click List Repository Contents to see the contents of the tables. A page displays similar to the one shown in Figure 3.



    Figure 3:  Repository Contents

  1. To retrieve the page, click the file name.

  2. To delete an entry from the database, click the delete link next to it.


    Setting Up the Environment
For information about creating and maintaining the database, refer to the database documentation.

For information about using the PointBase database with Sun Java System Web Server, refer to How to Run Sample Applications With PointBase.

For information about using the Oracle database with Sun Java System Web Server, refer to How to Run Sample Applications With Oracle.

Note - Make sure that the necessary parameters for running the samples are specified in install_root/samples/java/webapps/common.properties.


Compiling and Assembling the Application


To compile and assemble the sample application, complete the following steps:

  1. If you want to run the sample on an Oracle database, you must use the following script to create the table blob_repository: install_root/samples/java/webapps/jdbc/blob/src/sql/blob-ora.sql

    If you want to run the sample on a PointBase database, you must use the following script to create the table blob_repository: install_root/samples/java/webapps/jdbc/blob/src/sql/blob-pb.sql

  2. See How to Run Sample Applications With PointBase or How to Run Sample Applications With Oracle.

  3. JDBC datasource can be created with the Administration GUI or CLI, or with the following method. Make sure the necessary parameters for creating the JDBC resource are specified in the jdbc.build.properties file under the install_root/samples/java/webapps/jdbc directory. If you created the JDBC datasource using the Administration GUI or CLI, make sure that you added the JDBC driver jar files into the class-path-suffix element.

  4. Compile and assemble the WAR file by changing to the source directory at install_root/samples/java/webapps/jdbc/blob/src and running the ant command.

    The default target default is executed to build the WAR file
    .

  5. Execute ant create_datasource to create the data source.

    This creates the jdbc-resource element. Based on the jar files specified in the class.path.suffix property, the jar files will be added to the class-path-suffix element.
    For information about using the Administration GUI or CLI to create the data source, refer to Deploying Samples and Creating the Resources Using Admin GUI.

    Note - If you want to delete the data source, execute ant delete_resource.

  6. Deploy the application.

    After you have re-created the sample application from scratch, you can proceed to Deploying the Sample Application.

  7. (Optional.) Clean the web application project area.

    # ant clean

    This removes the assemble and build directories for the sample application. The WAR file is now ready for deployment.
Deploying the Sample Application

To deploy the sample application, complete the following steps:

  1. Change to the source directory at install_root/samples/java/webapps/jdbc/blob/src.

  2. Run the ant tool using the deploy task.

    # ant deploy

If you want to verify registration of the application, proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
 

Verifying Deployment

To verify the registration and deployment of the application, complete the following steps:

  1. Change to the source directory at install_root/samples/java/webapps/jdbc/blob/src.

  2. Run the ant tool using the list_apps task.

    # ant list_apps

The jdbc-blob module is listed as one of the components.
 

Running the Sample Application

You can run the application through the following URL:

http://Sun_Java_System_Web_Server_hostname:port/jdbc-blob

Undeploying the Sample Application

After successfully deploying and running the application, you might decide to undeploy it and remove the files. To undeploy the application
, complete the following steps:
  1. Change to the source directory at install_root/samples/java/webapps/jdbc/blob/src.

  2. Run the ant tool using the undeploy task.

    # ant undeploy

  3. Run the ant tool using the delete_resource task.

    # ant delete_resource

     
    This removes the deployed resource.

Troubleshooting

The file size should not exceed 102,400 KB, defined as the BLOB size in blob.sql. If you have a larger file, you need to modify the blob.sql file in install_root/samples/java/webapps/jdbc/blob/src/sql and then execute the sql in the database.



Copyright © 2007 Sun Microsystems, Inc. All rights reserved.