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

5. Suppose we have a JDBC Connection object c to a database, and this database h

ID: 3588604 • Letter: 5

Question

5. Suppose we have a JDBC Connection object c to a database, and this database has a relation R(name, address, phone) Columns name and address are of string type, while phone is an integer. The following objects are also declared: Statement s = null; String q = "SELECT address, phone FROM R" + "WHERE name = 'Bill Gates'". ResultSet r null; There are many methods that could be applied to the given variables. When a method is applied to r, assume that it holds the result of query q. Then, identify a correct use of a method from the list below. 0 a) String x = r.getInt (1); 0 b) r = c. executeQuery (g) ; O c) int p = r.getInt (2); O d) r = s.executeQuery ( );

Explanation / Answer

Hello there,

* First of all, Correct Answer is C) i.e. int p = r.getInt(2), because in the query we are expecting integer type i.e. phone on second position of column, so we are fetching an interger value by applying getInt() method on available resultset 'r'.

* Now i will explain why other options are incorrect, so it will be easily understandable for you.

* in a), they are applying getInt(1) method on the first field of query which is a string type i.e. address so, this can not be possible.

* in b) it is calling executeQuery function on query 'q' but this function can be called by only statement object and 'c' is connection object, so this is also wrong.

* in d) yes this time they called method with correct statement object 's' but this time they did not pass any parameter, that must be the object of query 'q'. So this is also wrong.

* Finally C) is our correct option, as mentioned the reason above.

Hope, you got your answer. Feel free to ask any query and to give feedback.

Thank you

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