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

3.3. Simple SQLJ Statements

In this section, you will learn how to write a program that contains simple SQLJ statements that use embedded SQL Data Manipulation Language (DML) statements. DML consists of the following types of statements:

  • SELECT

  • INSERT

  • UPDATE

  • DELETE

You will also learn how SQLJ statements can share data with other Java statements in the program through the use of host variables. At the end of this section, there is a complete example program that retrieves and modifies some of the data stored in the fundamental_user database schema.

3.3.1. The Form of a SQLJ Statement

A SQLJ executable statement is a program line that contains an embedded SQL statement. There are two possible types of executable statements, determined by whether or not the embedded SQL statement returns a value.

3.3.1.1. Statements that do not return a value

If an embedded SQL statement does not return a value, the syntax of the SQLJ executable statement is:

#sql { SQL_statement };

The syntax element is as follows:

SQL_statement

Specifies any valid SQL statement.

The following SQLJ executable statement invokes a SQL INSERT statement to add a row to the customers table:

#sql {
  INSERT INTO
    customers (id, first_name, last_name, dob, phone)
  VALUES
    (1, 'John', 'Smith', '13-NOV-1970', '650-555-1212')
};

Everything to the right of the #sql token in the syntax is the executable part of the SQLJ statement, known as the SQLJ clause. There are two types of SQLJ clauses. Because this SQLJ clause does ...

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