AnyLogic
Expand
Font size

Update element

Update connectivity tool is used to update database tables. You define the update object once and then you can use it to update the specified database table whenever you need.

Defining update object

To define update object

  1. Drag the Update  element from the Connectivity stencil of the Palette onto the graphical diagram.
  2. In the Properties view, modify the Name of the element. This name will be used to identify and access this update object.
  3. Specify the database you want to modify. Type the name of the AnyLogic database in the Database edit box (you can use code completion assist here).
  4. In the Table edit box, type the name of the database table you want to update with new values.
  5. In the Key Column field, specify the key column of the table. When updating rows of the database table, the value specified for this particular column will be used to identify the table row the user wants to update.
  6. Now you should define in the Key and value columns table, what particular columns of the database table you will update. The first non-editable column of the table contains the name of the key column you have specified previously. In the succeeding columns you should specify names of the columns you will update. To add new columns into the Key and value columns table, successively double-click in the rightmost column of the table and enter the name of the required column of the database table there.
  7. To delete some column of the Key and value columns table, select this column by clicking on it and then click the little cross button in the upper right corner of the column.
  8. Now you should define a set of values you want to add into the database table in the table Values. Values are defined row by row: in the first column you define value of the key column and in the succeeding columns you define values you want to update in the table row holding the specified value of the key column. You may leave some cells blank and enter values only in required columns.
  9. To add a value, first double-click in the corresponding cell of the table and then enter the value there.
  10. To delete some row of the Values table, select this row by clicking on it and then click the little cross button to the right of the table.

Properties

General

Name — The name of the update object. The name is used to identify and access this object from code.

Show name — If selected, the name of this update object is displayed on a presentation diagram.

Ignore — If selected, this update object is excluded from the model.

Show at runtime — If selected, this update object is visible on a presentation at runtime.

Database — The name of AnyLogic database object associated with the actual database you want to modify.

Table — The name of the database table you want to update with new values.

Key column — The key column of the table. When updating rows of the database table, the value specified for this particular column will be used to identify the table row the user wants to update.

Key and value columns — Here you specify, what particular columns of the database table you will update. The first non-editable column of the table contains the name of the key column you have specified previously. In the succeeding columns you should specify names of the columns you will update. To add new columns into the Key and value columns table, successively double-click in the rightmost column of the table and enter the name of the required column of the database table there.

Values — Here you specify a set of values you want to add into the given database table. Values are defined row by row: in the first column you define value of the key column and in succeeding columns you define values you want to update in the table row holding the specified value of the key column. You may leave some cells blank and enter values only in required columns. To add a value, first double-click in the corresponding cell of the table and then enter the value there.

Modifying the database using update object

Update the database table using the corresponding API of the Update object. The most frequently needed function is the following:

  • int execute() — Performs update of rows with current values. The function returns the number of modified rows.
How can we improve this article?