7.5.2 Perform Data Manipulation Using the UpdaTable ResultSet Object
Generally, performing data manipulation using the updaTable ResultSet can be divided into the following three categories:
• Data insertion
• Data updating
• Data deleting
Different data manipulations need different steps, and Table 7.6 lists the most popular steps for these data manipulations.
It can be seen from Table 7.6 that data deletion is the easiest way to remove a piece of data from the database, since it only takes one step to delete data from both the ResultSet and the database. The other two data manipulations, data update and insertion, need at least two steps to complete.
The point to be noted is that in the data insertion action, the first step, moveToInsertRow(), is moved to a blank row that is not a part of the ResultSet but related to the ResultSet. The data inser-tion actually occurs when the insertRow() method is called and the next commit command is executed.
Let’s start with the data insertion against our sample database first. In the following sections, we will use the Oracle database as our target database and build code to perform data manipulations against our target sample database.
7.5.2.1 Insert a New Row Using the UpdaTable ResultSet
To save time and space, we want to use and modify a project, OracleDeleteFaculty, we built in Section 7.4 to make it our new project to perform this data insertion action. Perform the following operations to make it our project:
1) Create a new folder, ClassDB Projects\Chapter 7, on your computer if you did not already do that, launch Apache NetBeans IDE 12 and open the Projects window.
2) Right-click on the project OracleDeleteFaculty we built in Section 7.4 and select the Copy item from the popup menu to open the Copy Project wizard.
3) Change the project name to OracleUpdaTableInsert in the Project Name box.
4) Browse to the folder Class DB Projects\Chapter 7, which was created in step 1, and click on the OK button to select this location as your project location.
5) Click on the Copy button to complete the copy process.
Perform the following code modifications to the FacultyFrame Form:
1) Open the constructor of this class and add one more statement into this constructor,
ComboMethod.addItem(“Java UpdaTable ResultSet”);
Your modified code in this constructor should match that shown in Figure 7.16. The modi-fied part is in bold.
2) Click on the Design button to switch back to the design view of the FacultyFrame form window, and double-click on the Insert button to open its event handler. Enter the code shown in Figure 7.17 into this handler to perform the data insertion action against our sample database.