1Z0-829 · Question #30
Given the course table: COURSE_ID COURSE_NAME COURSE_FEE COURSE_LEVEL 1021 Java Programmer 400.00 1 1022 Java Architect 600.00 2 1023 Java Master 800.00 3 Given the code fragment: try (Connection…
The correct answer is C. true. Option C (true) as marked is almost certainly an error in the answer key - and understanding why helps more than accepting it at face value. PreparedStatement.executeUpdate() always returns a primitive int (the row count), never a boolean. Since COURSE_LEVEL = 1 matches only…
Question
Options
- A2
- Bfalse
- Ctrue
- D1
How the community answered
(27 responses)- A4% (1)
- B15% (4)
- C78% (21)
- D4% (1)
Explanation
Option C (true) as marked is almost certainly an error in the answer key - and understanding why helps more than accepting it at face value.
PreparedStatement.executeUpdate() always returns a primitive int (the row count), never a boolean. Since COURSE_LEVEL = 1 matches only one row ("Java Programmer"), the call returns 1, and System.out.println(1) prints 1 - making D the logically correct answer. Option A (2) is wrong because only one row matches the WHERE clause. Option B (false) would be the result if execute() (not executeUpdate()) were called - execute() returns false for DML statements since no ResultSet is produced. Option C (true) cannot occur because executeUpdate() is not declared to return boolean under any overload. There is also a secondary bug: con.prepareStatement(sql, TYPE_SCROLL_INSENSITIVE) invokes the two-parameter overload prepareStatement(String, int autoGeneratedKeys), but passes TYPE_SCROLL_INSENSITIVE (value 1004) where only Statement.RETURN_GENERATED_KEYS (1) or NO_GENERATED_KEYS (2) are valid - this would likely throw a SQLException at runtime on most drivers, meaning none of the numeric outputs would even be reached.
Memory tip: Know your three execute methods cold - execute() → boolean, executeUpdate() → int, executeQuery() → ResultSet. Exam questions frequently swap them to test exactly this distinction.
Topics
Community Discussion
No community discussion yet for this question.