~/ 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/e17f6566-5fd0-4dc0-a6b0-8b23459362fb/flashcard utf-8 LF