JDBC BLOB Sample Application

> JDBC BLOB Sample Application
> This document describes how to use the JDBC BLOB sample application in conjunction with Sun ONE Web Server.

> This sample application document contains the following sections:

> Overview

> - Compiling and Assembling the Application

> - Deploying the Sample Application

> - Running 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 them to insert, update, delete, and fetch the files. The file 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. If you want to try binary data instead, 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, do the following:

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

> Figure 1 Upload Form

> Select a file and press the Upload button.

> 2. The UploadServlet is invoked.

>    This servlet will insert the file as BLOB (or a similiar data type) into the database.

> 3. The servlet will render a page similar to the one displayed in Figure 2

> Figure 2 Upload Result

> Press UpLoad to upload another file

> - or -

> Press List Repository Contents to see the contents of the tables. You should see a page similar to the one displayed in Figure 3.

> Figure 3 Repository Contents

> To retrieve the page, click the file name.

> 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 ONE Web Server, refer to How to run sample applications with Pointbase.
> For information about using the Oracle database with Sun ONE Web Server, refer to How to run sample applications with Oracle.

> Compiling and Assembling the Application

> This section contains instructions for compiling and assembling the sample application.

> 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>/plugins/java/samples/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>/plugins/java/samples/webapps/jdbc/blob/src/sql/blob-pb.sql.

> 2. Make sure you have added the JDBC driver jar to the classpathsuffix in server.xml.
>    Refer to How to run sample applications with Pointbase or How to run sample applications with Oracle.

> 3. Make sure the necessary parameters for creating the jdbc and connection pool resources are specified in the build.xml file, as follows:
>    For the PointBase server database:
>    <!-- ======================================================= -->
>    <!-- data source & connection pool properties -->
>    <!-- ======================================================= -->
>    <property name="jdbc.datasource.name" value="jdbc/jdbc-blob"/>
>    <property name="jdbc.datasource.poolname" value="jdbc-blob-pool"/>
>    <property name="jdbc.connectionpool.poolname" value="jdbc-blob-pool"/>
>    <property name="jdbc.connectionpool.classname" value="com.pointbase.jdbc.jdbcDataSource"/>
>    <property name="jdbc.connectionpool.url" value="DatabaseName=jdbc:pointbase:server://<host name>/<database name>,User=<user name>,Password=<password>"/>
>    For an Oracle database:
>    <!-- ======================================================= -->
>    <!-- data source & connection pool properties -->
>    <!-- ======================================================= -->
>    <property name="jdbc.datasource.name" value="jdbc/jdbc-blob"/>
>    <property name="jdbc.datasource.poolname" value="jdbc-blob-pool"/>
>    <property name="jdbc.connectionpool.poolname" value="jdbc-blob-pool"/>
>    <property name="jdbc.connectionpool.classname" value="oracle.jdbc.pool.OracleDataSource"/>
>    <property name="jdbc.connectionpool.url" value="URL=jdbc:oracle:thin:@<host name>:<port>:<sid>,User=<user name>,Password=<password>"/>

> 4. Go to <install_root>/plugins/java/samples/webapps/jdbc/blob/src and execute the ant command.
>    The target 'default' will be executed to build the WAR file.
>    Execute ant create_connectionpool to create the connection pool.
>    Execute ant create_datasource to create the data source.
>    (For information about using the Administration GUI to create the connection pool and data source, refer to Deploying Samples and Creating the Resources using Admin GUI.)
>    Then, restart the web server instance.
>    NOTE:
>    (a) Whenever you deploy or undeploy the connection pool and data source resource, you must restart the web server instance.
>    (b) If you want to delete the connection pool or change the connection pool properties, make sure you have already undeployed the relevant data source.
>    (c) If you want to delete the connection pool, execute ant delete_jdbcconnectionpool.
>    (d) If you want to delete the data source, execute ant delete_resource.

> 5. Deploy the application.
>    After you have created the sample application from scratch, you can proceed to Deploying the Sample Application. Step 6 is optional.

> 6. To remove the sample application assemble and build directories (optional), execute the following command:
>    ant clean

> Deploying the Sample Application

> To deploy the sample application, perform the following steps:

> 1. Go to the src directory of the sample: <install_root>/plugins/java/samples/webapps/jdbc/blob/src

> 2. Run ant 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

> 1. Go to the src directory of the sample as follows: <install_root>/plugins/java/samples/webapps/jdbc/blob/src

> 2. Execute the following command:
>    ant list_apps

> > You will see the jdbc-blob module displayed as one of the listed components.

> Undeploying the Application

> 1. Go to <install_root>/plugins/java/samples/webapps/jdbc/blob/src
> 2. Execute the following command:
>    ant undeploy

> Running the Sample Application

> You can run the application through the following URL:

> http://<Web_Server_hostname>:<port>/jdbc-blob

> Troubleshooting

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

> Copyright © 2003 Sun Microsystems, Inc. All rights reserved.