This sample demonstrates how to use the IBM Decision Optimization Modeling with OPL custom data source API to import data from a JDBC data source into an OPL model.
This sample illustrates the Subclassing IloCustomOplDataSoource section from the OPL User's manual. This sample shows how to read and write tuplesets to/from a database with Java. It also enables you to read a database and generate .dat files to be used in the IDE to prototype your optimization model.
One variation of this sample shows how to read and write tuplesets to/from a database involving only some scripting in your .dat
This sample comes with example connection configurations to DB2, MySQL and MS SQL Server. It can be easily adapted to any database that has JDBC drivers. This example will work with any 12.x OPL version, even if it is configured to run with 12.8.0 version.
-
This sample assumes that IBM ILOG CPLEX Optimization Studio 12.8.0 is installed and configured in your environment.
-
Install Java.
Once installed, you can check that it is accessible using this command:java -version
-
Install Apache ant.
-
The sample assumes you have a database with JDBC drivers installed. This sample specifically provides instructions for IBM DB2 Express-C and MySQL Comunity Server, but is compatible with minimal changes with other JDBC compatible databases.
Before you run, you need to populate the database. See details in subsections:
The examples/oil sample demonstrates how to create a Java application with a custom data source and invoke OPL from Java.
The examples/studio_integration sample shows how to
use the jdbc custom data source as a library, without having the need to
invoke OPL runtime from java. You can use this method to access database
using a jdbc-custom-data-source from oplrun
or OPL Studio.
- When running the
ant
command with the DB2/mysql target, simply add-Dexport=result.dat
on the command line, and it will export all the tuplesets that have been extracted from the database toresult.dat
file.
- Edit the build.xml at the root of the directory, and adapt the
example.home
variable to point to your 12.x version. - Recompile the project
- The custom data source reader supports scalar values, sets and tuplessets. Arrays are not supported.
- Inner tuples are not supported.
This sample is delivered under the Apache License Version 2.0, January 2004 (see LICENSE.txt).