Java OCA OCP Practice Question 2490

Question

Given that method getConnection() returns a valid Connection object, the query variable defines a valid SQL statement, and class Main prints 0, select the options for the following code that can be correct individually:.

class Main {/*  w  w w.  jav a 2s .c  om*/
    public static void main(String[] args) {
        try {
            String query = ".....";                        //line1
            Connection con = getConnection();
            PreparedStatement statement =
                           con.prepareStatement(query);
            System.out.println(
                statement.executeUpdate());
        }
        catch (SQLException e) {
            System.out.println(e);
        }
    }
}
  • a Line 1 defines a SQL SELECT statement that returned zero rows.
  • b Line 1 defines a SQL UPDATE statement that affected zero rows.
  • c Line 1 defines a SQL DELETE statement that affected zero rows.
  • d Line 1 defines a SQL CREATE TABLE statement, which would always return zero rows.


b, c, d

Note

You can't use method executeUpdate() to execute a SQL SELECT query.

If you do, you'll get a SQLException with a similar message:.

java.sql.SQLException: Can not issue executeUpdate() for SELECTs

Similarly, you can't execute data deletion and modification queries with method executeQuery().

If you do so, you'll get a SQLException.




PreviousNext

Related