Java Reference
In-Depth Information
{ SELECT EmployeeID, Name, DNR FROM EmployeeSchema.Employee };
}
}
Observe that the order is the same for the table, iterator, and SQL statement. To retrieve data from a
positional iterator, you must use the FETCH INTO statement and the endfetch() method to verify if
the end of the data has been reached as follows:
while (true) {
#sql {FETCH : MyPosIter INTO :EmployeeID, :Name, :DNR} ;
if (MyPosIter.endFetch()) {
break;
}
}
As with other database objects, it is important to close every iterator using the close() method to
free the occupied resources.
When compared to JDBC, SQLJ programs are usually more concise and thus easier to debug. As dis-
cussed, SQLJ also allows you to do syntactic and semantic query checking at design time, in contrast
to JDBC where queries are verified at runtime. Despite its advantages, the SQLJ standard has been
less popular than JDBC in the industry.
pushing complex data processing to the dataBase
SQL is a very powerful database manipulation language that allows complex data-
processing operations in the RDBMS itself. When using JDBC or SQLJ, it is highly
recommended to push as many complex data operations as possible to the database
instead of programming them in Java. Every RDBMS has built-in sophisticated facili-
ties for indexing and caching, which have a huge impact on query performance.
In the first JDBC example in this chapter, the SQL query performs a join between
two tables. Alternatively, you could opt to retrieve the data from both tables into
the Java program and program the join in Java. However, from a performance
viewpoint, this is highly discouraged as it would create more network traffic and
processing time. Hence, it is of key importance that a Java developer accessing a
RDBMS through JDBC or SQLJ possess a deep understanding of SQL in order to
write high-performing Java database applications!
ensuring oBJect persistence
During Java program execution, a distinction can be made between transient objects, which only exist
during program execution, and persistent objects, which need to be permanently stored in a database.
Earlier in this chapter, you learned about the impedance mismatch problem, which refers to the intrin-
sic incompatibility between Java objects and relational SQL tables. To bridge this incompatibility
problem, two solutions can be pursued. A first solution is to use an object relational mapping (ORM)
framework, which tackles the impedance problem by directly mapping Java objects to relational
 
 
Search WWH ::




Custom Search