Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Create a Data Access Object for Dynamics 365 Data using JDBI
A brief overview of creating a SQL Object API for Dynamics 365 data in JDBI.
JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for Dynamics 365 integrates connectivity to live Dynamics 365 data in Java applications. By pairing these technologies, you gain simple, programmatic access to Dynamics 365 data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write Dynamics 365 data.
About Dynamics 365 Data Integration
CData simplifies access and integration of live Microsoft Dynamics 365 data. Our customers leverage CData connectivity to:
- Read and write data in the full Dynamics 365 ecosystem: Sales, Customer Service, Finance & Operations, Marketing, and more.
- Extend the native features of Dynamics CRM with customizable caching and intelligent query aggregation and separation.
- Authenticate securely with Dynamics 365 in a variety of ways, including Azure Active Directory, Azure Managed Service Identity credentials, and Azure Service Principal using either a client secret or a certificate.
- Use SQL stored procedures to manage their Dynamics 365 entities - listing, creating, and removing associations between entities.
CData customers use our Dynamics 365 connectivity solutions for a variety of reasons, whether they're looking to replicate their data into a data warehouse (alongside other data sources)or analyze live Dynamics 365 data from their preferred data tools inside the Microsoft ecosystem (Power BI, Excel, etc.) or with external tools (Tableau, Looker, etc.).
Getting Started
Create a DAO for the Dynamics 365 GoalHeadings Entity
The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.
public interface MyGoalHeadingsDAO {
//insert new data into Dynamics 365
@SqlUpdate("INSERT INTO GoalHeadings (Name, Name) values (:name, :name)")
void insert(@Bind("name") String name, @Bind("name") String name);
//request specific data from Dynamics 365 (String type is used for simplicity)
@SqlQuery("SELECT Name FROM GoalHeadings WHERE Name = :name")
String findNameByName(@Bind("name") String name);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to Dynamics 365
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Dynamics 365.
Edition and OrganizationUrl are required connection properties. The Dynamics 365 connector supports connecting to the following editions: CustomerService, FieldService, FinOpsOnline, FinOpsOnPremise, HumanResources, Marketing, ProjectOperations and Sales.
For Dynamics 365 Business Central, use the separate Dynamics 365 Business Central driver.
OrganizationUrl is the URL to your Dynamics 365 organization. For instance, https://orgcb42e1d0.crm.dynamics.com
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Dynamics 365 JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.dynamics365.jar
Fill in the connection properties and copy the connection string to the clipboard.

A connection string for Dynamics 365 will typically look like the following:
jdbc:dynamics365:OrganizationUrl=https://myaccount.operations.dynamics.com/;Edition=Sales;InitiateOAuth=GETANDREFRESH
Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.
DBI dbi = new DBI("jdbc:dynamics365:OrganizationUrl=https://myaccount.operations.dynamics.com/;Edition=Sales;InitiateOAuth=GETANDREFRESH");
MyGoalHeadingsDAO dao = dbi.open(MyGoalHeadingsDAO.class);
//do stuff with the DAO
dao.close();
Read Dynamics 365 Data
With the connection open to Dynamics 365, simply call the previously defined method to retrieve data from the GoalHeadings entity in Dynamics 365.
//disply the result of our 'find' method
String name = dao.findNameByName("MyAccount");
System.out.println(name);
Write Dynamics 365 Data
It is also simple to write data to Dynamics 365, using the previously defined method.
//add a new entry to the GoalHeadings entity
dao.insert(newName, newName);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Dynamics 365 by integrating with the CData JDBC Driver for Dynamics 365. Download a free trial and work with live Dynamics 365 data in custom Java applications today.