| 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
- Compiling and Assembling the Application
- Deploying the Sample Application
- Running the Sample Application
- Undeploying the Sample Application
- Troubleshooting
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:
- Bring up a web page with a form like the one shown in Figure 1.
Figure 1: Upload Form
- 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
- 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
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:
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
See How to Run Sample Applications With PointBase or How to Run Sample Applications With Oracle.
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.
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.
- 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.
Deploy the application.
After you have re-created the sample application from scratch, you can proceed to Deploying the Sample Application.(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:If you want to verify registration of the application, proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.
- Change to the source directory at install_root/samples/java/webapps/jdbc/blob/src.
Run the ant tool using the deploy task.
# ant deploy
To verify the registration and deployment of the application, complete the following steps:
- Change to the source directory at install_root/samples/java/webapps/jdbc/blob/src.
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:
- Change to the source directory at install_root/samples/java/webapps/jdbc/blob/src.
- Run the ant tool using the undeploy task.
- 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.