Skip to content
Sharp

SQL for Java Devs · interview question

Why would you choose to use PreparedStatement over Statement in JDBC?

Multiple choiceMediumchapter-8-curatedpremiumsql-for-java-devsresultsets-and-mapping
Choose one answer
Answer and explanation

Correct answer

A. It prevents SQL injection attacks.

Why

PreparedStatement helps prevent SQL injection attacks by allowing you to set parameters using placeholders, which are safely handled by the database, avoiding direct string concatenation in SQL queries.

Test yourself on SQL for Java Devs

A free test with instant, explained results. No account needed.

Start free test
All SQL for Java Devs questions →