4. Create a SQLj project to retrieve student name and faculty name from STUDENT and FACULTY tables respectively. Use host variables declared in Java program and display retrieved rows. (Iterator problem)

What will be an ideal response?

```
import oracle.sqlj.runtime.*;
import sqlj.runtime.*;
import sqlj.runtime.ref.*;
import java.io.*;
import java.sql.*;
public class StudentFaculty {
public static void main(String [ ] args) {
#sql iterator DeptIter(String, String, String);
String l=null;
String f=null;
String n=null;
try {
Oracle.connect
("jdbc:Oracle:thin:@localhost:1521:oracle",
"nshah", "india_usa", true);
DeptIter di = null;
#sql di =
{
SELECT Last l, first f, name n
FROM student s, faculty f
WHERE s.FacultyId = f.FacultyId
};
#sql {fetch :di into :l, :f, :n};
while (!di.endFetch( )) {
System.out.println(l+"\t"+f+"\t"+n);
#sql {fetch :di into :l, :f, :n};
}
di.close( );
}
catch (SQLException e) {
System.out.println(e.getMessage( ));
}
finally {
try {
Oracle.close( );
}
catch(SQLException e) {
e.printStackTrace( );
}
}
}
}
```

Computer Science & Information Technology

You might also like to view...

Microsoft Intune requires an on-premises server infrastructure before it can be deployed.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Group managers said it was OK for their people to attend a three-day JAD session next week. Send a message to the JAD team members, with a brief explanation of JAD methods and a proposed agenda.

What will be an ideal response?

Computer Science & Information Technology