Insert

Insert connectivity tool is used to perform row insertion into the database table. You define "insert" object once and then you can use it to insert new values into the specified database table whenever you need.

Defining "insert" object

 To define "insert" object

  1. Drag the Insert  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 "insert" 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, where you want to insert new values. 
  5. In the table Values to insert, specify values to be inserted into the specified database table and columns where these values should be placed. 
  6. You specify each value in the individual column: the name of the column you want to update is defined in the Column cell and the value itself is defined in the Expression cell.
  7. To add one more value, double-click into the Column cell of the rightmost column and enter the name of the column where you want to insert new value. In the same way enter this value (or expression evaluating the value) in the Expression cell below.
  8. To delete some column of the Values to insert table, select this column by clicking on it and click the little cross button in the upper right corner of the column.
General properties

Name – The name of the "insert" object. The name is used to identify and access this object from code.

Show name – If selected, the name of this "insert" object is displayed on a presentation diagram.

Ignore – If selected, this "insert" object is excluded from the model.

Show at runtime – If selected, this "insert" 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, where you want to insert new values. 

Values to insert – Here you specify values to be inserted into the given database table and columns where these values should be placed. You specify each value in the individual column: the name of the column you want to update is defined in the Column cell and the value itself is defined in the Expression cell. To add one more value, double-click into the Column cell of the rightmost column and enter the name of the column where you want to insert new value. In the same way enter this value (or expression evaluating the value) in the Expression cell below.

Inserting values into the database table using "insert" tool

Call the "insert" statement using the corresponding API of the Insert tool. The most frequently needed function is the following:

int execute() - Performs insertion of one row with current values. The function returns number of inserted rows (normally 1 row)