nerdexam
Oracle

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…

Accessing databases using JDBC

Question

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 con = DriverManager.getConnection(connectionString)) { Statement statement = con.createStatement(TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); String sql = "UPDATE course SET course_fee = ? where COURSE_LEVEL = ?"; PreparedStatement prst = con.prepareStatement(sql, TYPE_SCROLL_INSENSITIVE); prst.setDouble(1,800.00); prst.setInt(2,1); System.out.println(prst.executeUpdate()); } catch (SQLException sqlException) { System.out.println(sqlException); } What is the result?

Options

  • A2
  • Bfalse
  • Ctrue
  • D1

How the community answered

(27 responses)
  • A
    4% (1)
  • B
    15% (4)
  • C
    78% (21)
  • D
    4% (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

#JDBC PreparedStatement#executeUpdate()#SQL UPDATE#row count

Community Discussion

No community discussion yet for this question.

Full 1Z0-829 Practice