[英]How can I access hsql database through raw data files i.e. without an API or connector?
[英]How to get an excel spreadsheet into anylogic database, without importing it i.e. using code on the main startup
以前我以常用的方式导入了我的 Excel 电子表格。 现在我想通过在 main 中编写代码来自动获取我的信息。 到目前为止,我已经编写了以下内容来获取单个单元格,但我想了解如何从多行多列中获取信息。
insertInto(db_table).columns(db_table.db_column).values(data.getCellNumericValue("Sheet1", 5, 4)).execute();
只需在所有工作表 ( getNumberOfSheets()
)、所有列 ( getLastCellNum(row)
) 和所有行 ( getLastRowNum()
) 中使用 for 循环。
在AnyLogic 帮助中详细介绍了 API 调用(底部):)
如果您想通过代码自动上传数据表,而不是依赖 AnyLogic 复选框,您可以使用以下内容(来自上一个项目的示例):
public void importTableDataOnStartup(java.sql.Connection internalDatabaseConnection) throws Exception {
try (DatabaseDescriptorRegistry r = new DatabaseDescriptorRegistry()) {
java.sql.Connection cachedSourceConnection;
cachedSourceConnection = r.getConnection(DatabaseDescriptorFactory.createFileDescriptor( Utilities.findExistingFile("..\\ExcelData\\" + ebFileName.getText() + ".xlsx"), null, ""));
UtilitiesDatabase.copyDatabaseTable(cachedSourceConnection, internalDatabaseConnection, "\"PhysicianTypes\"", "physician_types");
UtilitiesDatabase.copyDatabaseTable(cachedSourceConnection, internalDatabaseConnection, "\"PatientFlow\"", "patient_flow");
UtilitiesDatabase.copyDatabaseTable(cachedSourceConnection, internalDatabaseConnection, "\"Referrals\"", "referrals");
UtilitiesDatabase.copyDatabaseTable(cachedSourceConnection, internalDatabaseConnection, "\"Incident Patient Rate\"", "incident_patient_rate");
UtilitiesDatabase.copyDatabaseTable(cachedSourceConnection, internalDatabaseConnection, "\"PatientDeathRates\"", "patient_death_rates");
traceln("Database import is complete.");
}
}
在上面的代码中,用户可以通过编辑框(ebFileName.getText())选择一个Excel文件名。 模型中已经设置了一些数据库表,这会更新它们。
我不得不这样做,因为表太大了,每次更新表都需要 30 秒的启动时间。 实际上,我的客户确实不需要更改这些表,但想要一种“以防万一”的机制。 我们在实验窗口上添加了一个按钮,让他们可以根据需要在启动时上传。
我请求 AnyLogic 添加一个 table.upload() 类型的命令来使这更容易。 他们说它在他们未来版本的开发列表中,但我还没有在他们的发行说明中看到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.