🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Checking AI-Written SQL: all 10 questions

Quiz: Checking AI-Written SQL · Question 8 of 10

Which is the safe way to use a user-typed name in a query?

Which is the safe way to use a user-typed name in a query?

  1. A.f"SELECT * FROM students WHERE name = '{name}'"
  2. B."SELECT * FROM students WHERE name = '" + name + "'"
  3. C.db.execute("SELECT * FROM students WHERE name = ?", (name,))
  4. D.Remove quotes from the name and paste it in
Answer & explanation

Correct answer: db.execute("SELECT * FROM students WHERE name = ?", (name,))

Parameters keep data separate from SQL code and prevent SQL injection.

Can you get the rest right without peeking?

Take the timed Quiz: Checking AI-Written SQL quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →