1.3 Errors Want To Be Caught

One of the first lines in your SQLJ program will be

    import java.sql.SQLException;

Whenever something goes wrong while running your SQLJ program, your SQLJ statements and any methods in the SQLJ runtime API throw a SQLException. Either declare that your program throws a SQLException, or put

    try { ... } catch (SQLException exn) { ... }

blocks in your program.

  • For more details on SQLExceptions in SQLJ, see SQLJ Developer's Guide and Reference, Chapter 4, Section "Exception-Handling Basics".
  1. (*) Create the following file test.sqlj:
    public class test {
    public static void main(String[] args) {
    #sql { ROLLBACK };
    } }
    What do you see when you run sqlj test.sqlj? Why? How can you fix this? After fixing and translating, run java test. What happens? Why? Now read Section "1.4 Getting Connected" and fix this problem.
  2. (***) A SQLException can originate from the database, from JDBC, or from SQLJ itself. Can you write a SQLJ program that creates all three kinds of errors at runtime? Hint: you might want to translate this program offline, and you also want to read up on SQLJ-JDBC interoperability — see Section "5.1 A Dynamic Program".

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy