RimuDB Logo
Database Access Framework for Java

Generic Update

While GenericQuery is useful for issuing database selects, the GenericUpdate class is useful for issuing database updates and deletes.

To use GenericUpdate, the caller specifies the database and SQL statement. Like GenericQuery, prepared statements are used, so the SQL statement can contain parameter markers. The caller then calls the executeUpdate() method, passing an array of parameter values. The framework performs the statement execution, handles the connections, and returns an int value indicating the number of rows affected.

An example of a delete operation:


public int deleteItemsFromLocation(String itemNumber, String warehouseLocation) throws RimuDBException {
	Database db = cdb.getDatabase(InventoryDO.class);

	String sql = "DELETE FROM {InventoryDO} WHERE item_number = ? AND location = ?";

	GenericUpdate update = new GenericUpdate(db, sql);
	Object parameters[] = new Object[2];
	parameters[0] = itemNumber;
	parameters[1] = warehouseLocation;
	return update.executeUpdate(parameters);
}

An example of an update operation:


public int resetReceiveDates(String itemNumber, String warehouseLocation) throws RimuDBException {
	Database db = cdb.getDatabase(InventoryDO.class);

	String sql = "update {InventoryDO} set receiveDate = '0001-01-01 00:00:00' where itemNumber = ? and location = ?";

	GenericUpdate updater = new GenericUpdate(db, sql);
	Object parameters[] = new Object[2];
	parameters[0] = itemNumber;
	parameters[1] = warehouseLocation;
	return updater.executeUpdate(parameters);
}