Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What does the following programming example is the SQIJ (in Java)-in Figure 9.8,

ID: 3686755 • Letter: W

Question

What does the following programming example is the SQIJ (in Java)-in Figure 9.8, processing multiple tuples at a time, declaration of variables is given.) What does the program segment J2A do? What does line 0 do? What do lines (2 to 3) do? What do lines (4 to 1) do? What does line 9 do? What docs line 10 do? What do lines (11 to 12) do? What does line 13 do? What do lines (14 to 15) do? What is the purpose of the iterator in SQIJ On which linc(s)) and with what command is the named iterator declared? On which linc(s)) and with what command is the named iterator associated with a query; On which linc(s)) and with what command is the named iterator moved to the next row in the result of the query?

Explanation / Answer

About SQLJ ITERATOR

General Steps in Using an Iterator

Five general steps are involved in using either kind of SQLJ iterator:

1.     Use a SQLJ declaration to define the iterator class (in other words, to define the iterator type).

2.     Declare a variable of the iterator class.

3.     Populate the iterator variable with the results from a SQL query, using a SELECT statement.

4.     Access the query columns in the iterator (how to accomplish this differs between named iterators and positional iterators, as explained below).

5.     When you finish processing the results of the query, close the iterator to release its resources.

Named Iterators versus Positional Iterators

There are advantages and appropriate situations for each of the two kinds of SQLJ iterators.

Named iterators allow greater flexibility. Because data selection into a named iterator matches SELECT-fields to iterator columns by name, you need not be concerned about the order in your query. This is less prone to error, as it is not possible for data to be placed into the wrong column. If the names don't match, the SQLJ translator will generate an error when it checks your SQL statements against the database.

Positional iterators offer a familiar paradigm and syntax to developers who have experience with other embedded-SQL languages. With named iterators you use a next() method to retrieve data, while with positional iterators you use FETCH INTO syntax similar to that of Pro*C, for example. (Each fetch implicitly advances to the next available row of the iterator before retrieving the next set of values.)

A)

This J2A segment will do the following

first it takes the input from the user

Dname=readEntry(“ enter the department name:”)

After excuting the line following ouput is obtaned

enter the department name:lakshmi

and than

select Dnumber into:dnumber

from Department where Dname=:dname

this line project or extract the dnumber the given input and stored departnames are equal

(i.e iam enter the ( enter the department name:lakshmi) if it is there in stored database than departnumber of the lakshmi is projected)

if the entered department name does not exit than try throws an exception , catch SQLException and prints the Department does not exit

and than it prints the employee information for department:eee(example eee)

for excuting multiple row query results ie employee ssn ,fname,minit lname,salay

This line will project or extract the employee ssn,fname,minit,lname,salary, from employee table whose Dno and dnumers are equal.

And than e.next called

it is used for named iterator moved to the next row in the result of the query

than finally prints the

it is used for prints the employee ssn ,fname,minit lname,salay

example like 4555 laki lll korada 4555555

sample output::

enter the department name:lakshmi

employee information for depapartment:lakshmi

4555 laki lll korada 4555555

b)

Dname=readEntry(“ enter the department name:”)

This line takes the input of department name

After excuting the line following ouput is obtaned

enter the department name:

c)

select Dnumber into:dnumber

from Department where Dname=:dname

this line project or extract the dnumber the given input and stored departnames are equal

(i.e iam enter the ( enter the department name:lakshmi) if it is there in stored database than departnumber of the lakshmi is projected)

d)

4 t0 7 line the following

if the entered department name does not exit than try throws an exception , catch SQLException and prints the Department does not exit

e)

in the line 9 named iterator is declared

When you declare a named iterator class, you declare the name as well as the datatype of each column of the iterator.

When you select data into a named iterator, the SELECT-fields must match the iterator columns in two ways:

f) Emp e=null this command used for initialization or declaration of employee variables to null.

g)

general rules of select in named iterator

When you select data into a named iterator, the SELECT-fields must match the iterator columns in two ways:

Given question solution is

This line will project or extract the employee ssn,fname,minit,lname,salary, from employee table where Dno=:dnumber

ie This line will project or extract the employee ssn,fname,minit,lname,salary, from employee table whose Dno and dnumers are equal.

h)

it is used for named iterator moved to the next row in the result of the query

ie while(e.next)

generally purpose of next is

Use the next() method of the named iterator object to step through the data that was selected into it. To access each column of each row, use the accessor methods generated by SQLJ, typically inside a whileloop.

Whenever next() is called:

i) it is used for prints the employee ssn ,fname,minit lname,salay

example like 4555 laki lll korada 4555555

j)

purpose of iterators in SQLJ

Multi-Row Query Results--SQLJ Iterators

Additionally, Oracle SQLJ offers extensions that allow you to use SQLJ iterators and result sets in the following ways:

k)

i)in the line 9 named iterator is declared

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote