Image Database
is a sample Java Servlet application that demonstrates how JDBC 3-Tier model works.
Client.html
is an interface at client side, which offers a form for querying the Image Database. The form consists of a table with four fields: Image Name, Color, Type and Url. User can fill in values in those fields or leave unknown value as a blank. The request to Servlet server is done by Form "input" Event Handlers and handles "get" Forms.
ImageDBServlet
is a middle-tier module at server side, which accepts request from client and
responses. In the Image Database application, ImageDBServlet collects query (form values) from client and forms query command for
accessing the Image Database by method of myDatabase through JDBC. The important method for implementing communication with client side is doGet(HttpServletRequest req, HttpServletResponse res), which matches the form method "get" in client.html file. This module also responsible for sending back query results from Database to client in the form of HTML file. One of the advantages of doing this is that the HTML file can be displayed in any browser. User will see images showing up in the browser, rather than URL, as I built link to image source in the HTML file.
myDatabase
implements methods to access the Oracle database via JDBC. The API includes
open and close database, executeSQL for executing query commands and getRecord for returning multiple records that matches
the query. Vector object
is used to hold multiple
Hashtables
as elements, where each record is held by a hashtable. As
each query is packaged into a string object
that deliverd to execution method. so all of the database access
methods take executeSQL and getRecord as the underline methods. And it is very flexible to expand the functions of
query based on this scheme. I use oracle.jdbc.driver.OracleDriver
to connect to the Oracle database on Carver.
The database access part of the program is done on server side using the above JDBC driver. The myDatabase class implements two important methods executeSQL and getRecord.
The demo applet works with
Netscape Communicator versions 4.5, 4.04
with AWT 1.1 patch and 4.05 with AWT 1.1 patch on Solaris machines.
To run the demo
Click here
.
The program consists of three distinct modules:
Back to Top Page
Design Notes
Back to Top Page
Source
client.html
ImageDBServlet.java
myDatabase.java
table.sql
Image Database Servlet
Back to Top Page
Demo
Back to Homework Page