- Built on top of JDBC
- Enables developers to write less code to embed SQL statements in Java Programs
- A preprocessor is used to translate SQLJ into Java code using JDBC calls to database. TO USE SQLJ your compiler must support this!!!!!
- These SQL statements are actually checked at compile-time and hence allow for increased error detection (in JDBC pass SQL queries as strings...no error checking at compile time)
JDBC Program (from E-Commerce book)
Java.sql.CallableStatement stmt; //Setup Connection conn = DriverManager.getConnection("jdbc:default"); //prepare statement to execute //Use positional parameters to set variables //Execute query and store results |
Equivalent SQLJ Program (from E-Commerce
book)
ResultSet res; #sql res = (SELECT empno, ename FROM emp WHERE sal > :sal_p
AND deptno = :deptno_p); //pass the above throug the SQLJ translator and will
|