Describe use of iterators in SQLj projects.
What will be an ideal response?
When a SQL query returns more than one row in a Java program, SQLj iterator is used.
An iterator is similar to JDBC result set, but columns are given data types in iterator. An
iterator is based on cursor in the SQL query. SQLj constructs an iterator class for iterator
declaration. The instance variables and methods from iterator class are available in the
program. There are two types iterator declarations:
? Named Iterator – data types and column names are specified.
? Positional Iterator – only data types are specified.
Named Iterator: The following statement declares a named iterator DeptIter.
#sql iterator DeptIter(int i, String n, String l);
Iterator contains three columns with their data type. SQLj creates a class with the same
name, DeptIter. Then, a null reference named di to DeptIter class is declared, which is
populated with a SELECT query. It is important to use column aliases for columns
retrieved, and column aliases must be same as column names in the iterator.
DeptIter di = null;
#sql di={SELECT deptid i,deptname n,location l FROM dept};
Positional Iterator: Positional iterator is similar to named iterator, but it is declared with
data types that positionally match data types of columns retrieved with the SELECT
query. For example, the positional iterator is declared only with data as follows:
#sql iterator DeptIter(int, String, String);
The iterator is instantiated and populated with a SQL query as given in the following
statements:
DeptIter di = null;
#sql di = {SELECT deptid, deptname, location FROM dept};
You might also like to view...
Case-Based Critical Thinking QuestionsCase 6-2Wyona, owner of Wyona's Hat Designs, desires to have a Web site built for customers to order custom-made hats. They can pick from straw, leather, and material hat collections. Customers can specify one of their existing patterns, which include about 50 designs. They can also choose a custom pattern instead and then provide information about the pattern they want for Wyona to custom create. For her address she wants to make sure the zipcode is set to 5 characters only. Which attribute of a text box will allow her to do this?
A. maxlength B. size C. length D. characters
Digital signatures are designed to address ________.
a) privacy b) authorization c) authentication d) nonrepudiation
The head command displays the first ____ lines of a text file.
A. two B. five C. ten D. 100
The technician needs to map a network share to the user' s Windows 7 computer from the command prompt. Which of the following commands will the technician execute?
A. NET SEND B. NET CONFIG C. NET USE D. NET NAME