I got the insert and Delete Data/Row working for my DBMS.
The deleteRow method finds the row that contains the same primary key from the database, passed on to the method, and deletes the row.
With using the insertRow method, the data I added shows on up on the last row as I wanted.
My problem is when I do a combination of calling the insert, delete multiple times the row inserted shows up on the position where the last deleted row was**
**when I delete the newly inserted row positioned at the deleted row and inserts it again it now shows up on the last row
My Questions is:
How do I make sure that the inserted row will always be at the last row no matter how many times I delete,insert or update the data.
Here's my current code:
public void insertRow(String Mname, String Genre, int price,
String date) throws SQLException {
Statement stmt = null;
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery("SELECT MOVIE_NAME, GENRE, FILM_BUDGET, RELEASE_DATE FROM MOVIE");
try {
uprs.moveToInsertRow();
uprs.updateString("MOVIE_NAME", Mname);
uprs.updateString("GENRE", Genre);
uprs.updateInt("FILM_BUDGET", price);
uprs.updateString("RELEASE_DATE", date);
uprs.insertRow();
uprs.moveToCurrentRow();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
} finally {
if (uprs != null) { uprs.close(); }
if (stmt != null) { stmt.close(); }
}
}
void deleteRow(String Mname) throws SQLException{
Statement stmt = null;
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery("SELECT MOVIE_NAME, GENRE, FILM_BUDGET, RELEASE_DATE FROM MOVIE");
try {
uprs.last();
while( !(uprs.getString("MOVIE_NAME").equals(Mname)) ){
uprs.previous();
}
uprs.deleteRow();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
} finally {
if (stmt != null) { stmt.close(); }
if (uprs != null) { uprs.close(); }
}
}