Important Web Design and Development Short Questions
Chapter: 15
Question 1:
What is the purpose of the Connection.close() method?
Answer:
The Connection.close() method is used to close the database connection, releasing database resources and preventing potential memory leaks. It should be called once all database operations are complete.
Chapter: 16
Question 2:
What does a ResultSet in JDBC represent?
Answer:
A ResultSet represents the result of a SQL query and is displayed in a table format with rows and columns. It maintains a cursor that initially points before the first row and allows navigation and data retrieval from the result set.
Chapter: 16
Question 3:
How do you move the cursor to the next row in a ResultSet?
Answer:
You use the next() method to move the cursor to the next row. This method returns true if there is a next row available and false if the cursor is at the end of the result set. Before retrieving data, you must call next() at least once.
Chapter: 16
Question 4:
What is the difference between a default ResultSet and an updatable ResultSet?
Answer:
A default ResultSet is not updatable and only allows forward-only navigation. An updatable ResultSet allows both forward and backward navigation and supports updating, inserting, and deleting rows.
Chapter: 16
Question 5:
How can you create a scrollable and updatable ResultSet?
Answer:
You can create a scrollable and updatable ResultSet by using PreparedStatement with the parameters ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.CONCUR_UPDATABLE when calling prepareStatement().
Chapter: 16
Question 6:
What method would you use to move the cursor to the last row in a ResultSet?
Answer:
Use the last() method to move the cursor to the last row of the ResultSet. This method throws an exception if the ResultSet is of type TYPE_FORWARD_ONLY.
Chapter: 16
Question 7:
Describe how to update a row in a ResultSet.
Answer:
To update a row in a ResultSet, first move the cursor to the desired row, then use updateX() methods (e.g., updateString(), updateInt()) to set new values for columns. Finally, call updateRow() to apply the changes to the database.
Chapter: 16
Question 8:
What is the purpose of the moveToInsertRow() method in a ResultSet?
Answer:
The moveToInsertRow() method is used to move the cursor to a special insert row in a ResultSet, where new row values can be set. After setting the values, insertRow() must be called to insert the row into both the ResultSet and the database.
Chapter: 16
Question 9:
How do you delete the current row in a ResultSet?
Answer:
Use the deleteRow() method to delete the current row from the ResultSet and the underlying database. This method throws an exception if the cursor is positioned on the insert row.
Chapter: 16
Question 10:
Explain the use of absolute(int row) in a ResultSet.
Answer:
The absolute(int row) method moves the cursor to the specified row number. A positive number moves the cursor forward from the beginning, while a negative number moves it backward from the end.