- Connecting to MS Access or MS Excel database
- Connecting to the MS SQL Server database
- Connecting to the PostgreSQL database
- Connecting to the Oracle database
- Connecting to the MySQL or MariaDB database
- Connecting to other databases using JDBC/ODBC drivers
- Setting up the database connection on model startup
Database is an element of the AnyLogic model that represents an actual existing database and is responsible for communicating with it. By creating an instance of the Database element, you declare that your model can to access a corresponding database.
Demo model: Dumping Simulation Output into a Database Table Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).Follow one of the instructions in this article depending on the type of your database. To navigate, use the sidebar on the right.
To access an MS Access or MS Excel database in your model, you should link your model to an appropriate file. This approach is simple and does not require you to have anything other than one of the tools mentioned above. Its disadvantage is that it requires storing an absolute file path in an AnyLogic project. Therefore, if you change the location of a database, you must manually change the corresponding path in the AnyLogic project.
To connect AnyLogic to the MS Access or MS Excel database:
- Select the Database element you want to associate with Access file.
- In the Properties view, select Excel/Access from the Type drop-down list.
- Specify the database file to be associated. Click the Browse button. The Open dialog box appears.
- Browse to the MS Access file you want to use.
- Double-click the file or select it and click the Open button to select the file.
- If necessary, use the button to the right of the File field to toggle between the absolute and relative file paths.
To connect AnyLogic to the MS SQL Server database:
- Select the Database element you want to associate with the MS SQL Server database.
- In the Properties view, select MS SQL Server from the Type drop-down list.
- Specify the host computer in the Host field.
- In the Database name field, specify the name of the database you want to access.
- Enter Login and Password if required by the database.
To connect AnyLogic to the PostgreSQL Server database:
- Select the Database element you want to associate with the PostgreSQL Server database.
- In the Properties view, select PostgreSQL Server from the Type drop-down list.
- Specify the host computer in the Host field.
- In the Database name field, specify the name of the database you want to access.
- Enter Login and Password if required by the database.
To connect AnyLogic to the Oracle database:
- Select the Database element you want to associate with the Oracle database.
- In the Properties view, select Oracle from the Type drop-down list.
- Specify the host computer in the Host field.
- In the Database name field, specify the name of the database you want to access.
- Enter Login and Password if required by the database.
To connect AnyLogic to the MySQL\MariaDB database:
- Select the Database element you want to associate with the MySQL\MariaDB database.
- In the Properties view, select MySQL\MariaDB from the Type drop-down list.
- Specify the host computer in the Host field.
- In the Database name field, specify the name of the database you want to access.
- Enter Login and Password if required by the database.
The other way to connect to a database is to associate it with an JDBC/ODBC data source. This technique uses the so-called JDBC/ODBC drivers and makes your model independent of the database type and location.
To connect AnyLogic to a different type of database using JDBC/ODBC drivers
- Select the Database element you want to associate with an actual database.
- In the Properties view, select Other Database from the Type drop-down list.
-
Specify the JDBC driver you want to use in the JDBC Driver combo box.
You must have the specified driver defined in your system or this tool will not be available. Refer to the driver documentation for installation details.
- Enter the Connection URL for the JDBC driver. The string syntax depends on the driver you are using, so refer to the driver documentation again.
- Enter Login and Password if required by the database.
After the initial setup, you can interact with the database using the database API. You can also set up the model to connect to the database during startup.
To set up a model startup database connection
- Select the Database element in the graphical editor.
- In the Properties view, select the Connect on startup check box. AnyLogic will attempt to connect to the specified database at model startup.
-
How can we improve this article?
-