'"Error: java.sql.SQLException" When exporting database table to excel AnyLogic

I am trying to export a table from AnyLogic's database to an excel file in a parameters variation using this code:

Database myFile = new Database(this, "A DB from Excel", "DataBaseExport.xlsx");
ModelDatabase modelDB = getEngine().getModelDatabase();
modelDB.exportToExternalDB("flowchart_stats_time_in_state_log", myFile.getConnection(), "Sheet 1", true, true);

I am then given this error enter image description here

With this after

enter image description here



Solution 1:[1]

It turns out that the name of the excel sheet "sheet1" is the culprit. Upon removing the "1" and creating matching column names in the excel file, the data is able to be exported.

Solution 2:[2]

Not sure about your issue, but maybe try this instead:

  1. create a database object as below: enter image description here

  2. Call this code at runtime: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 NickA
Solution 2 Benjamin