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