I have a dropdown list that holds all the columns name from the table. When the user selects a certain column name and enters a specific value to search for along with two different dates, I get that information and update the table as shown below.
But before updating I want to prompt a dialog box asking the user “This many rows will be updated, do you want to do this?”. Can I modify something in this code to get that count before it’s updated or is there a better way to do this?
sql.append(" UPDATE Table_jack ");
sql.append(" set date = to_date('" + this.getNewDate() + "','MM/DD/YYYY')");
if ((this.getSelectedDDL() != null)&& (this.getSelectedDDL().equals("1"))){
sql.append(" where id_nbr =" + this.getValue() + "'");
sql.append(" and date between to_date('" + this.getDateFrom() + "','MM/DD/YYYY') and to_date('" + this.getDateTo() + "','MM/DD/YYYY')");
}
if ((this.getSelectedDDL() != null)&& (this.getSelectedDDL().equals("2"))){
sql.append(" where name =" + this.getValue() + "'");
sql.append(" and date between to_date('" + this.getDateFrom() + "','MM/DD/YYYY') and to_date('" + this.getDateTo() + "','MM/DD/YYYY')");
}
ResultSet rset = db.executeQuery(sql.toString(),true);
Rather than trying to get a count before you issue the update, get a count of the number of rows actually updated and display that to the user before issuing the
COMMIT(orROLLBACK).The
Statement.executeUpdatemethod returns the number of rows that theUPDATEstatement modified. If you used that rather thanexecuteQuery, you could get a row count from theUPDATEstatement. You could then present that to the user before ending the transaction.