Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Search this book:
 
Search the site:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


Listing 3-1: An HTML form.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2//EN”>
<HTML>
<HEAD>
<TITLE>The CGI approach</TITLE>

</HEAD>
<BODY>
<H1>The CGI approach</H1>
<P>
<B>
/cgi-bin/emp_locator is a CGI which performs lookups in a database.
</B>
</P>
<P>
<HR>
<FORM METHOD=”POST” ACTION=”/cgi-bin/emp_locator”>
<B>Employee Locator</B>
</P>
<P> Search on (multiple)
<SELECT NAME=”LookFor” MULTIPLE>
<OPTION SELECTED>Name
<OPTION>Title
<OPTION>Department
<OPTION>Location
</SELECT>
</P>
<P>which
<SELECT NAME=”How”>
<OPTION SELECTED>starts with
<OPTION>contains
<OPTION>is exactly
<OPTION>sounds like
</SELECT>
</P>
<P>the following:
<INPUT TYPE=”text” NAME=”Match-pattern”>
</P>
<P>
<INPUT TYPE=”checkbox” NAME=”Use-Case” VALUE=”Yes”>Case-sensitive
</P>
<P>
<INPUT TYPE=”submit” VALUE=”Submit”>
</FORM>
<HR>
</P>
</BODY>
</HTML>

This HTML document displays the form in the browser window shown in Figure 3-9.


Figure 3-9:  The CGI approach — HTML forms.

A Java applet that was downloaded from the network may perform some communication with the server from where it originated. Two kinds of mechanisms may be used to give an applet data that resides in a database.

In the first mechanism the applet connects itself to the server via the java.net.URL Connection class and asks the WWW server to initiate a common gateway interface that connects to the database, eventually sending it some parameters. This CGI application then forwards data to the applet as shown in Figure 3-10.


Figure 3-10:  An applet using a proprietary protocol.

In this case, a Java applet sends the data used as input to the CGI application. As soon as the CGI retrieves the data from the database, it sends it back to the applet. This process is more interactive than the simple HTML form. Figure 3-11 shows such an applet.


Figure 3-11:  The Java applet approach.

There are two ways to send parameters to a CGI application: HTML GET form submission and HTML POST form submission. In the case studied here, the Java applet must mimic one of these ways. Here is an example of what must be sent along with the URL to perform a GET submission:

http://torremolinos/cgi-bin/emp_locator?LookFor=Name
&How=contains&pattern=Bernard

On the other hand, an HTML POST submission from Java will look like this:

POST /cgi-bin/emp_locator HTTP/1.0
Content-type: application/x-www-form-urlencoded
Content-length: 42
{your data goes here}
LookFor=Name&How=contains&pattern=Bernard
...

On behalf of data that was previously entered via HTML forms, the CGI application may build a custom HTML page containing an <APPLET> tag to tell the browser that an applet has to be downloaded. It can add <PARAMETERS> tags filled with data extracted from the database using the user’s data that was previously entered through the HTML form, as shown in Figure 3-12.


Figure 3-12:  An applet receiving data from its parameters.

Listing 3-2 is an HTML form that is sent back to the client browser. It contains the applet tag and information passed as applet parameters. Such an HTML document is typically sent after a submission of values from an HTML form:

Listing 3-2: An HTML form.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2//EN”>
<HTML>
<HEAD>
<TITLE>The CGI approach</TITLE>

</HEAD>
<BODY>
<H1>The CGI approach</H1>
<P>
<B>
/cgi-bin/emp_locator is a CGI which performs lookups in a database.
</B>
</P>
<P>
<HR>
<B>Employee Locator</B>
</P>
<APPLET CODE=myApplet width=600 height=500>
<PARAM NAME=name VALUE=’Bernard Van Haecke’>
<PARAM NAME=title VALUE=’Java evangelist’>
<PARAM NAME=location VALUE=’BXL’>
</APPLET> <HR>
</P>
</BODY>
</HTML>

The first method to connect applets to a database is used when an interface is needed to build the query. The second connection method may be used only to process the results after an HTML POST or HTML GET submission.

While these approaches work, they have some inherent limitations. Because CGI applications add overhead to the WWW server, take care to avoid overloading the server.

Java Wrapper Classes

Java wrapper classes usually do not use JDBC classes to perform a database connection and send/retrieve data to and from the database. On the contrary, they often use native methods and libraries that are, by definition, not portable. They also offer a higher level of abstraction by mapping rows of data to Java objects data members, providing a solution to the impedance mismatch between SQL and Java.

Using JDBC with an ODBMS

While JDBC and JDBC drivers must support at least ANSI SQL-92 Entry Level, there are no limitations on the kind of statements that may be submitted to the Database Management System. An application query may be a specialized derivative of SQL. Many Object Database Management Systems (ODBMS) vendors have endorsed the JDBC specification. They will probably provide higher-level APIs to map directly stored objects to Java classes. The goal is to offer a persistent service for Java classes, without worrying about specific DBMS-API access issues that make programming more difficult and less efficient from a developer’s point of view. Object databases are particularly well suited to store multimedia information. Among other kinds of data, they offer enhanced facilities to handle, store, retrieve, and query HTML documents, images, free text, video, audio, multidimensional graphics, and even Java objects. All these multimedia objects, if considered as persistent data members of an object-oriented programming language such as C++, Smalltalk, or Java, may then be manipulated very easily within such languages.

Using an Object/Relational DBMS Bridge

An Object/Relational DBMS bridge is a software tier that presents relational data in an object-oriented way and provides methods similar to those of ODBMSs. Like ODBMSs, such a bridge provides persistency to objects, but also integrates with a wide variety of relational DBMSs while exploiting their inherent specifications. An Object/Relational DBMS bridge may be used in conjunction with existing developments, thus preserving investments in resources such as relational DBMS engines, data they may contain, and physical resources associated with them. This software may be an alternative to using an Relational DBMS directly from JDBC.

Summary

This chapter discussed the integration of databases with Java using JDBC and other techniques, including:

  The role of JDBC
  The components of JDBC and their characteristics
  JDBC alternatives

The next chapter discusses the mechanisms, interfaces, and typical uses of JDBC.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.