Skip to content
Advertisement

SQL data types for AnyLogic

I am saving the output of my AnyLogic model into an SQL server database. For non-AnyLogic aficionados, AnyLogic is based on Java. However, I am not sure what data types I need to specify for my columns in the database.

So far I am using these:

  • double in AnyLogic : float in SQL
  • string in AnyLogic : varchar in SQL
  • int in AnyLogic : int in SQL

I also have parameters that are of type Option list, which is, if I understand correctly, a form of Java enum. I tried to save those parameters as varchar, but this (obviously) does not work. In addition, my model contains various boolean parameters. For my boolean parameters, I add columns of type bit in SQL by running:

ALTER TABLE myTable 
   ADD my_bool BIT NOT NULL DEFAULT 0;

However, running the model returns this error

SQLServerException: Invalid column name ‘false’. Caused by: Invalid column name ‘false’

So concretely, how can I export parameters of type Option list and boolean?

Advertisement

Answer

I managed to address part of my problem. I am now able to store String variables from Java into my SQL database. The issue was due to incorrect use of quotations.

Java uses double quotations for String variables (e.g.: ""). SQL expects single quotations (e.g.: '') for string-like columns such as varchar() and char()

I had to amend my SQL query to this: String insertTableSQL = "INSERT INTO test (my_string) VALUES(" +" '"+my_variable_string+"' )";

Note that my_variable_string is a derivative of a Java enum, which I obtained by executing String my_variable_string= my_enum.name();

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement