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.