1.5. A "Hello World" Program for SQLJ

Many programming books introduce new languages using a variation of the "Hello World" program. The classic "Hello World" program has a simple objective: to display the words "Hello World" on the screen. My version of "Hello World" uses SQLJ statements to connect to the database and retrieve the current date, which is then displayed on the screen. First, I'll show you the code required for this "Hello World" program; then I'll show how to compile and run it. By convention, SQLJ programs use the file extension .sqlj, so the "Hello World" program will be named HelloWorld.sqlj.

As mentioned in the Preface, source code for all the example programs in this book can be downloaded from the book's web site at O'Reilly, http://www.oreilly.com/catalog/orasqlj.

1.5.1. Example Program: HelloWorld.sqlj

The HelloWorld.sqlj program, shown in Example 1-1, performs the following tasks:

  1. Connects to the database.

  2. Retrieves the current date from the database.

  3. Displays a message containing the current date obtained in the previous step.

  4. Disconnects from the database.

Example 1-1. HelloWorld.sqlj
/* The program HelloWorld.sqlj illustrates how to connect to a database, and display the words "Hello World" along with the current date. */ // import required packages import java.sql.Date; import java.sql.SQLException; import oracle.sqlj.runtime.Oracle; public class ...

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.