Given a scrollable updatable ResultSet that contains the following, what does the code snippet output?.
color | count |
---|---|
character varying(255) | integer |
black | 20 |
blue | 5 |
red | 0 |
rs = stmt.executeQuery("select * from pens"); rs.afterLast(); rs.previous(); rs.updateInt(2, 10); rs.updateRow(); rs = stmt.executeQuery("select * from pens where color = 'red'"); while (rs.next()) System.out.println(rs.getInt(2));
B.
This code shows how to properly update a ResultSet.
Note that it calls updateRow()
so the changes get applied in the database.
This allows the SELECT query to see the changes and output 10.
Option B is correct.
Remember that unlike this code, you should always close a ResultSet when you open it in real code.