In my project I have to keep on inserting new rows in a table based on some logic. After this I want that each time an event is triggered, the rows of updated table should be fetched. But the Problem is that new rows aren't accessed. The table is always updated after i close the current simulation. A similar case was posted last year but the answer wasn't clear, and due to less reputation score I am unable to comment on it. Does anyone know that whether Anylogic 8.1.0 PLE supports reading of newly updated database table records at runtime or not? or is there some other beneficial solution?
1 Answers
This works correctly in AnyLogic (at least in the latest 8.2.3 version) so I suspect there is another problem with your model.
I just tested it:
- set up a simple 2-column database table;
- list its contents (via query) at model startup;
- update values in all rows (and add a bunch of rows) via a time 1 event;
- list its contents (via query) via a time 2 event.
All the new and updated rows show correctly (including when viewing the table in AnyLogic, even when I do this during the simulation, pausing it just after the changes).
Note that, if you're checking the database contents via the AnyLogic client, you need to close/reopen the table to see the changes if you were already in it when starting the run. This view does auto-update when you close the experiment, so I suspect that is what you were seeing. Basically, the rows had been added (and will be there when/if you query them later in the model) but the table in the AnyLogic client only shows the changes when closing/reopening it or when the experiment is closed.
Since you used the SQL syntax (rather than the QueryDSL alternative syntax) to do your inserts, I also checked with both options (and everything works the same in either case).
The table is always updated after i close the current simulation
Do you mean when you close the experiment?
It might help if you can show the logic/syntax you are using for your database inserts and your queries.

- 2,432
- 1
- 17
- 20
-
executeStatement("INSERT INTO chunks(chunk_id,chunk_size,data_id,src_id,dest_id,v_id) VALUES ('"+Data.chunk_id+"','"+chunk_size+"','"+Data.dataId+"','"+Data.srcId+"','"+Data.destId+"','"+this.vId+"')"); ------this is the insert statement i am using where Chunks is the name of the table, and this is working fine, closing the current simulation updates the table as required, but not in runtime – Murk Mar 28 '18 at 07:02
-
or may be I should try for the version 8.2.3 – Murk Mar 28 '18 at 07:09
-
OK, added some more detail based on your comments. Is this just because you have the table open in the AnyLogic client and expect to see the rows change after you insert them (without closing/opening the table in AnyLogic)? – Stuart Rossiter Mar 28 '18 at 11:23
-
It now works fine with the new version 8.2.3. Now I am finally able to read the updated data at runtime :).. thanks Stuart – Murk Mar 28 '18 at 11:24
-
OK great. Could you upvote the answer and accept it then please? – Stuart Rossiter Mar 28 '18 at 11:28
-
Accepted. but my vote might not appear publicly due to less reputation score – Murk Mar 28 '18 at 11:51