@@ -15,9 +15,9 @@ This example will work with any 12.x OPL version, even if it is configured to ru
1515
1616## Table of Contents
1717 - [ Prerequisites] ( #prerequisites )
18- - [ Build and run the sample from java] ( #build-and-run-the-sample-from-java )
18+ - [ Build and run the sample] ( #build-and-run-the-sample )
19+ - [ Run the 'oil' sample] ( #run-the-oil-sample )
1920 - [ Run the sample from OPL] ( #run-the-sample-from-opl )
20- - [ Reusing the sample with other databases] ( #reusing-the-sample-with-other-databases )
2121 - [ Export plain dat files] ( #export-plain-dat-files )
2222 - [ Run with another OPL version] ( #run-with-another-opl-version )
2323 - [ License] ( #license )
@@ -43,76 +43,25 @@ This example will work with any 12.x OPL version, even if it is configured to ru
4343
4444## Build and run the sample
4545
46- The default sample uses model and data from [ examples/oil] ( examples/oil ) .
4746Before you run, you need to populate the database. See details in subsections:
4847
4948- [ Run sample with DB2] ( README.DB2.md )
5049- [ Run sample with MySQL] ( README.MySQL.md )
5150- [ Run sample with MS SQL Server] ( README.SQLServer.md )
5251
52+ ### Run the 'oil' sample
53+
54+ The [ examples/oil] ( examples/oil ) sample demonstrates how to create a Java application with
55+ a custom data source and invoke OPL from Java.
5356
5457### Run the sample from OPL
5558
56- Sample in [ examples/ilo_opl_call_java ] ( examples/ilo_opl_call_java ) shows how to
59+ The [ examples/studio_integration ] ( examples/studio_integration ) sample shows how to
5760use the jdbc custom data source as a library, without having the need to
5861invoke OPL runtime from java. You can use this method to access database
5962using a jdbc-custom-data-source from ` oplrun ` or OPL Studio.
6063
6164
62- ### Reusing the sample with other databases
63-
64- As the sample is build on JDBC, it's possible to reuse <code >JdbcCustomDataSource</code > with minimal changes:
65-
66- * Add your JDBC driver in your classpath
67- * update db.xml with your database connection string
68-
69- ``` XML
70- <!-- The connection string
71- The default url connects to mysql on default port, using database
72- 'custom_data_source'
73- -->
74- <url>jdbc:mysql://localhost:3306/custom_data_source?useSSL=false</url>
75-
76- <!-- Your connection credentials -->
77- <user>sql_user</user>
78- <password>mysql</password>
79- ```
80-
81- * update db.xml with queries to read your data elements.
82-
83- ```XML
84- <read>
85- <query name="Gasolines">SELECT NAME FROM GasData</query>
86- <query name="Oils">SELECT NAME FROM OilData</query>
87- <query name="GasData">SELECT * FROM GasData</query>
88- <query name="OilData">SELECT * FROM OilData</query>
89- </read>
90- ```
91-
92- * update db.xml with your output data elements mapping to tables.
93-
94- ```XML
95- <write>
96- <!-- This maps the output dataset "Result" to the "result" table -->
97- <table name="Result" target="result"/>
98- </write>
99- ```
100- * Initialize a new <code >JdbcCustomDataSource</code >, read your database
101- configuration file and add your data source to OPL using
102- <code >IloOplModel.addDataSource()</code >.
103-
104- ```Java
105- JdbcConfiguration jdbcProperties = null;
106- String jdbcConfigurationFile = cl.getPropertiesFileName();
107- if (jdbcConfigurationFile != null) {
108- jdbcProperties = new JdbcConfiguration();
109- jdbcProperties.read(jdbcConfigurationFile);
110- // Create the custom JDBC data source
111- IloOplDataSource jdbcDataSource = new JdbcCustomDataSource(jdbcProperties, oplF, def);
112- // Pass it to the model.
113- opl.addDataSource(jdbcDataSource);
114- }
115- ```
11665
11766## Export plain dat files
11867* 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 to ` result.dat ` file.
0 commit comments