Exception Handling in SQLJ

SQLJ executable statements result in JDBC calls with the use of sqlj.runtime; therefore, SQLJ also needs to catch or throw SQL exceptions because of the SQL statements in SQLJ code blocks. In addition, SQLJ traps errors during compilation.

Handling SQLJ exceptions requires the use of the java.sql.SQLException class, which can be imported using either of the following import statements:

Import java.sql.SQLException

or

Import java.sql.*

The following is a code snippet from SqljDml.sqlj:

 /* Delete a record from the customers table using SQL DELETE statement*/ public void deleteRecord(String p_custid){ try{ // Delete a record using embedded SQL DELETE statement #sql { Delete from ow_customers where cust_id= :p_custid ...

Get e-Commerce Applications Using Oracle8i and Java from Scratch 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.