C.1. SQLJ in Applets

An applet is a program that may be downloaded and executed in a web browser, such as Netscape Navigator or Internet Explorer, and run using the Java Virtual Machine that comes with the browser. You can also run applets from the command line, which is helpful for debugging and testing purposes. This section shows a simple applet, named AppletExample.sqlj, that contains SQLJ statements, and describes how to compile and run this applet from the command line. For an introduction to applets, I recommend the book Learning Java by Patrick Niemeyer and Joshua Peck (O'Reilly).

AppletExample.sqlj (Example C-1) uses the Abstract Window Toolkit (AWT)—which contains windows, graphics, and user interface classes—to display customer details retrieved from the customers table. AppletExample.sqlj performs the following steps:

  1. Creates an AWT TextArea object to which customer details will be written.

  2. Creates an AWT GridBagLayout object into which the TextArea object is placed. A GridBagLayout object allows you to position UI components relative to one another. The GridBagLayout will be visible in the applet when it is executed.

  3. Connects to the fundamental_user schema using a DefaultContext object.

  4. Creates and populates an iterator object named cust_iterator, which stores the id, first_name, last_name, dob, and phone column values retrieved from the customers table.

  5. Populates the TextArea object with the customer details.

Example C-1. AppletExample.sqlj
/* AppletExample.sqlj ...

Get Java Programming with Oracle SQLJ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.