![]() |
JDBC BLOB Sample Application |
JDBC BLOB Sample Application
This document describes how to utilize the JDBC BLOB sample application in conjunction with Sun ONE Application Server version 7.This sample application document contains the following sections:
Overview
Compiling and Assembling the Application
Deploying the Sample Application
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 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, you should modify web.xml by changing true to false on lines 20 and 33.The repository is a simple database table containing a BLOB column (or similar datatype) which holds the file data along with the filename, size and mime type of the stored content.
To use the JDBC BLOB application, one would 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.
The servlet will render the page similar to the one displayed in Figure 2
- This servlet will insert the file as Blob (or similiar datatype) into the database.
![]()
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 on the file name.
To better understand the sample application source code, refer to the related javadocs which can be accessed at s1as_install_dir/samples/jdbc/blob/javadocs/index.html after it is generated.
- If you click the delete link, the entry will be deleted from the database.
Setting up the environment
In order to successfully deploy and run the JDBC BLOB sample application, Database resources (PointBase) needs to be setup with the Application Server.If you want to run the JDBC BLOB sample application with the Oracle database, please refer to (How to run samples with Oracle database server) for configuration steps.
Compiling and Assembling the Application
This section contains instructions to build and assemble the JDBC BLOB sample application using a Command Line Interface (CLI).
Go to s1as_install_dir/samples/jdbc/blob/src/
Deploy the application.
- Execute the command asant
Note You must add s1as_install_dir/bin to your path.
- The default target core will be executed to build the EAR file.
Clean the application project area (optional).
- After you have re-created the sample application from scratch, you may proceed to Deploying the Sample Application. Step 3 is optional.
- Execute the command asant clean to remove the sample application assemble and build directories.
- Now you are ready to use this ear file for deployment.
Deploying the Sample Application
In this section, you will learn how to deploy the JDBC BLOB sample application.Command Line-based Deployment describes how to manually register the application in Sun ONE Application Server using a Command Line Interface (CLI). This is the fastest means of deploying the sample application.
Since a complete EAR file is supplied, the fastest means of setting up the application is to use the command line utilities as described in this section.
The pre-built jdbc-blob.ear file is a Enterprise Archive file that contains the JAR file of the application. Within the JAR file resides the XML deployment descriptor files, application class files, and other content required by the application.
Deploying the pre-built jdbc-blob.ear file is simple. Deploy either by Using the asant script or by Using the asadmin command.
Go to the src directory of the sample. For example:
Run asant using deploy task. For example:
- s1as_install_dir/samples/jdbc/blob/src
- %asant deploy
Go to s1as_install_dir/samples/jdbc/blob/
The deployment process involves the following operations:
- asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> jdbc-blob.ear
Authenticates against the local application server's administrative server
If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.The EAR file is transferred to the administrative server
The administrative server begins the registration process:
Verifying Deployment
As an optional step, you can use the Sun ONE Application Server Administration Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.To verify the registration of the application, do the following:
Execute the command asadmin list-components to look at applications deployed with a server instance. For example:
asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> <server instance name>.
You will see jdbc-blob listed.
Undeploy the application
If you wish to undeploy the application after successful deployment, you may do so by either Using the asant script or by Using the asadmin command.
Go to s1as_install_dir/samples/jdbc/blob/src
- asadmin undeploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> jdbc-transactions
Running the Sample Application
The schema/table are prepopulated so you don't need to configure the database. When the application is deployed, the jdbc-connection-pool and jdbc-resource are already taken care of. If you want to understand how to create/delete the jdbc-connection-pool/jdbc-resource, please refer to build.xml.After the database is configured, you can run the appliction through the following URL:
http://<AppServer hostname>:<port>/jdbc-blob/UploadForm.html
Please make sure that you run asant undeploy before redeploying this sample. This will ensure that all modules are undeployed and the resources are disabled.
The file size should not exceed 102400 defined as the blob size in blob.sql. If you want to try on the larger file, you need to modify the blob.sql under s1as_install_dir/samples/jdbc/blob/src/sql. You should then run asant sql to recreate the data.
If you encounter problems when running the application, review the log files at s1as_install_dir/domains/<domain-instance> /<server-instance>/logs/server.log to learn what exactly went wrong.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.
Last Updated July 11, 2002