O'Reilly logo

Java Programming with Oracle SQLJ by Jason Price

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required