← Quiz: SQL Injection: all 10 questions
Quiz: SQL Injection · Question 7 of 10
Which JDBC code is safe?
Which JDBC code is safe?
- A.stmt.executeQuery("SELECT * FROM users WHERE id = " + id)
- B.conn.prepareStatement("SELECT * FROM users WHERE id = ?") followed by ps.setInt(1, id)
- C.stmt.executeQuery(String.format("SELECT * FROM users WHERE id = %s", id))
- D.Removing quotes from id and concatenating
Answer & explanation
Correct answer: conn.prepareStatement("SELECT * FROM users WHERE id = ?") followed by ps.setInt(1, id)
PreparedStatement sends the value separately from the SQL.
Can you get the rest right without peeking?
Take the timed Quiz: SQL Injection quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →