Which type of Statements can execute parameterized queries?

  1. O (a) PreparedStatement

  2. O (b) ParameterizedStatement

  3. O (c) ParameterizedStatement and CallableStatement

  4. O (d) All kinds of Statements (i.e. which implement a sub interface of Statement)


Correct Option: A

AI Explanation

To answer this question, we need to understand the concept of parameterized queries and the types of statements that can execute them.

Parameterized queries are SQL statements that contain placeholders for input parameters. These placeholders are then replaced with actual values when the query is executed. Parameterized queries provide several benefits, including improved security and performance.

Now let's go through each option to understand which type of statements can execute parameterized queries:

Option A) (a) PreparedStatement - This option is correct because PreparedStatement is a type of statement that can execute parameterized queries. It allows you to precompile a SQL statement with placeholders and then set the actual parameter values before executing the query. This helps in preventing SQL injection attacks and improves performance by reusing the precompiled statement.

Option B) (b) ParameterizedStatement - This option is incorrect because there is no such type of statement called ParameterizedStatement.

Option C) (c) ParameterizedStatement and CallableStatement - This option is incorrect because while PreparedStatement can execute parameterized queries, CallableStatement is used specifically for executing stored procedures and does not support parameterized queries.

Option D) (d) All kinds of Statements (i.e. which implement a sub interface of Statement) - This option is incorrect because not all types of statements can execute parameterized queries. Only PreparedStatement, which is a sub-interface of Statement, supports parameterized queries.

Therefore, the correct answer is option A) (a) PreparedStatement. This option is correct because PreparedStatement is the type of statement that can execute parameterized queries.

Find more quizzes: