Connecting to external Database with ODM API
The IBM ODM Decision Center and the Rule Execution Server values are stored, by default, in a Derby database that comes with the IBM ODM suite installation. During a rules development project we sometimes need to access these values and insert them on an external database or update this external database accordingly. In this post I will show you how to connect to an external Datase with the ODM API in java and execute a simple query after collecting Decision Center values. You can use this method in your project with any values you need from the Decision Center.
To understand the basics of the ODM API, please refer to my previous post about the IBM ODM API here.
- Preparing Decision Center Values
- Connecting to an External DB
- Let’s create a new Java class with the Connection details.
- It is a good practice to have the value of the connection datasource in a properties file.
- Create a getConnection() method in the DBConnection class and add the following structure:
- Return the con variable and call this method from the main ODM API java class:
Now you are ready to execute any statement in the external DB using the Decision Center variables. Query statement sample: ps = con.prepareStatement(“INSERT INTO db.dt VALUES (‘”+ruleProject.getName())
I hope you enjoy this tutorial and please feel free to contact me with any query or feedback, thank you!
- Published in Debug, Decision Center, Decision Table, Java, ODM API, Rule Designer