Connecting to a MySQL db with the anylogic objects

780 views Asked by At

I'm trying to connect to a local MySQL database, with the anylogic object "database".

I'm using the type: "Other Database", and the connection URL: "Server=localhost;Database=anylogicdata;"

but I constantly get a RuntimeException saying: "not suitable driver found" The help file says that you have to install the driver, but i don't know which or if it is my connection URL that is the problem.

Does anyone have some pointers to help me along the way?

2

There are 2 answers

0
Nikolaj Klitlund Børty On BEST ANSWER

First you have to download and add the mysql-connector-java-*.jar file to the anylogic-project. Then you have to type com.mysql.jdbc.Driver into the JDBC driver dropdown box. finally the connection string should look something like

jdbc:mysql:[host/db]?:[port]

another thing I found that might be helpfull to others, is that you can get the java connection from the anylogic db object: database.getConnection() this is very usefull if you want to create your own query. eg create a bulk insert instead of the single insert that Anylogic provides.

3
T_D On

You need a JDBC driver to be able to connect to a MySQL server from Java (that AnyLogic is based on) and you can find one here. After you have installed the driver you should find it in the list of available JDBC drivers in AnyLogic. The name should be com.mysql.jdbc.Driver if you chose the suggested one.