Skip to content
Sharp

SQL for Java Devs · interview question

How can you safely execute a user-supplied search term in a SQL query using a PreparedStatement?

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

Correct answer

A. Bind the search term using setString

Why

To safely execute user-supplied input, you should bind the input using methods like setString in a PreparedStatement. This ensures that the input is treated as data rather than executable SQL code, preventing SQL injection.

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 →