~/ learn/ java-from-zero/ cards/ Querying with PreparedStatement and ResultSet
1 of 4

Type a PreparedStatement query with a placeholder

Type a PreparedStatement query with a placeholder

Answer

PreparedStatement ps = conn.prepareStatement( "SELECT name FROM users WHERE id = ?"); ps.setInt(1, userId); ResultSet rs = ps.executeQuery();

prepareStatement sends the SQL template to the database. setInt(1, ...) binds the first ? placeholder. executeQuery runs the query and returns a ResultSet.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/e5b5d7b5-0da2-43fc-a3dc-0d88be881a61/flashcard utf-8 LF