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:





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


Specifies any valid SQL statement.

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

#sql {
    customers (id, first_name, last_name, dob, phone)
    (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 ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.