fgbologah3
fgbologah3

Reputation: 11

Getting JDBC Driver load error while importing Excel data into Anylogic database

I am new to Anylogic and Java in general. I am trying to do something very simple. I have an Anylogic simulation model that imports data from an Excel file into the in-built database using the "Create or import table" link in the properties window.

Now instead of using the "Create or import table" of the in-built database, I want to programmatically read the data in the Excel file into the in-built database. I look Anylogic Help and found a page that explains how to "To import data from an Excel table into the model’s database programmatically".

I followed the instructions and created the code in the "on start up" action box of main. However, I keep getting this error:

Error during model startup:
Database ("Store Data"): Couldn't load database JDBC Driver "com.googlecode.sqlsheet.Driver" (class   not found)
java.lang.RuntimeException: Database ("Store Data"): Couldn't load database JDBC Driver       "com.googlecode.sqlsheet.Driver" (class not found)
at com.anylogic.engine.connectivity.Database.<init>(Unknown Source)
at com.anylogic.engine.connectivity.Database.<init>(Unknown Source)
at com.anylogic.engine.connectivity.Database.<init>(Unknown Source)
at testdatabase.Main.onStartup(Main.java:319)
at com.anylogic.engine.Agent.d(Unknown Source)
at com.anylogic.engine.Agent.start(Unknown Source)
at com.anylogic.engine.Engine.start(Unknown Source)
at com.anylogic.engine.ExperimentSimulation.g(Unknown Source)
at com.anylogic.engine.ExperimentSimulation.run(Unknown Source)
at com.anylogic.engine.ExperimentSimulation.b(Unknown Source)
at com.anylogic.engine.internal.k$k.run(Unknown Source)

Can you please look at my code below and let me know why I am getting this JDBC Driver load error?

ModelDatabase modelDB = getEngine().getModelDatabase();
Database myStoreFile = new Database(this, "Store Data", "Ryan_sim_data_02226.xlsx");
modelDB.importFromExternalDB(myStoreFile.getConnection(), "loc_forecast", "Internal_loc_forecast", true, false);

Upvotes: 0

Views: 131

Answers (1)

John
John

Reputation: 6785

I was able to create this error on my AnyLogic 8.8.1 installation. When this error occurs, it appears to be related to calling new Database() to read the excel file. But the real issue seems to be that by the time AnyLogic gets to that code, it has already decided that you don't need the database driver.

To prevent this error, you can create an empty database table (and then delete it again, if you like).

Right click on Database > New > Database table:

Right click on Database > New > Database table

Choose "Create an empty table".

Choose "Create Empt

You will now have a table in the database.

enter image description here

You can even delete this table if you like. But creating the table will create a database folder, containing files db.script and db.properties. It seems that when the AnyLogic startup detects these files, it loads the database driver file that you need.

Thanks to my colleague Christelle for finding the solution!

Upvotes: 0

Related Questions