Sean Zhang wrote:I have several questions on Inserting New Rows Using a ResultSet. Can you please take a look?
Sean Zhang wrote:Question 1: Can I delete line 3, so that the cursor is pointing above the first row before we move the cursor to the insert row? Is this allowed?
Sean Zhang wrote:Question 2: After executing line 8, where is the new row inserted in the database? Is it always appended in the end of the database as the last row no matter where the cursor was pointing in the result set before it was moved to the insert row?
Sean Zhang wrote:Question 3: After executing line 8, if I want to insert another new row, do I need to add another line "rs.moveToInsertRow();" in the code?
Sean Zhang wrote:Question 4: Between the line 7 and line 8, if I add a new line "rs.next();", will this lead to throw SQLException in runtime because next() method is not allowed when the cursor is in the insert row?
Sean Zhang wrote:But unfortunately, I have no access to a database, and that's why I did not run experiments myself.
Sean Zhang wrote:Question 2: The ResultSet gives us a means to insert rows into the database, but any such rows cannot have been among the results when the query was executed, right? And my question is: where is the new inserted row in the database's table? (Is it true that the new inserted row is always put as the last row in the database's table?)
Sean Zhang wrote:Question 3: The reason why I ask this question is I have seen a code used by Java doc which calls the moveToInsertRow() method a second time when they insert a second row. Please check the following webpage:
Still you think it is not necessary to call the moveToInsertRow() method a second time when they insert a second row?
Sean Zhang wrote:Question 4: So you mean the next() method can be called even when the cursor is in the insert row?
Sean Zhang wrote:Dear Roel,
Thank you for your detailed reply and useful info. Although I didn't run experiments myself for JDBC, fortunately this is the only place which confused me. Since I thought there was no way for me to access a database to run experiments myself for JDBC, I decided to post my very first question here and yes, this is my first time. Thank you for your patience and help!
Last, for those who are preparing for OCP 804 exam, I'd say JDBC is among one of the easiest chapters! After carefully reading K&B7 from cover to cover, I am confident not only to pass the OCP 804 exam, but also to face the incoming interviews! (It took me 6 days to finish the 1st part of K&B7, OCA, and another 6 weeks to finish the 2nd part of this book, OCP.)