Our goal is to retrieve the name of all professors in a particular department from the Professor table given by


Professor(Id: INTEGER, Name: STRING, DeptId: DEPTS)


The department will be supplied at run time. Assume a connection object, con, has been
created.
(a) Write the JDBC statement used to create a prepared statement object pre for this query.
If the statement involves a host variable, give its value at the time the JDBC statement is
executed.

(b) Suppose we want to get the names of all professors in the CS Department using the prepared statement object pre. What JDBC statements must be executed to put these names
in a results set, res.

(c) What JDBC statement must be executed to fetch the rst name from res?


(a) Write the JDBC statement used to create a prepared statement object pre for this query.
If the statement involves a host variable, give its value at the time the JDBC statement is
executed.
Solution:


PreparedStatement pre = con.prepareStatement
( ``SELECT P.Name FROM Professor P WHERE P.DeptId = ?'')

(b) Suppose we want to get the names of all professors in the CS Department using the prepared statement object pre. What JDBC statements must be executed to put these names
in a results set, res.
Solution:

pre.setString(1, ``CS'') (or pre.setString(``DeptId'', ``CS'') )
ResultSet res = pre.executeQuery( )


(c) What JDBC statement must be executed to fetch the rst name from res?
Solution:

name = res.getString(1) (or name = res.getString(``Name'') )

Computer Science & Information Technology

You might also like to view...

Why do you not get an undefined reference in virtual table error when you don’t define a pure virtual function?

What will be an ideal response?

Computer Science & Information Technology

A(n) ________ table is the table to which you are appending the fields in an append query

Fill in the blank(s) with correct word

Computer Science & Information Technology

Before reviewing a document you should ensure that your user name and initials are recorded in Word Options

Indicate whether the statement is true or false

Computer Science & Information Technology

Which of the following is a malware program designed to replicate without attaching to or infecting other files on a host system?

What will be an ideal response?

Computer Science & Information Technology