![]() |
VOOZH | about |
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 Business Central integrates connectivity to live Dynamics 365 Business Central data in Java applications. By pairing these technologies, you gain simple, programmatic access to Dynamics 365 Business Central data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read and write Dynamics 365 Business Central data.
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 MyAccountsDAO {
//insert new data into Dynamics 365 Business Central
@SqlUpdate("INSERT INTO Accounts (Name, Name) values (:name, :name)")
void insert(@Bind("name") String name, @Bind("name") String name);
//request specific data from Dynamics 365 Business Central (String type is used for simplicity)
@SqlQuery("SELECT Name FROM Accounts WHERE Name = :name")
String findNameByName(@Bind("name") String name);
/*
* close with no args is used to close the connection
*/
void close();
}
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Dynamics 365 Business Central.
To authenticate to Dynamics 365 Business Central, you must select an AuthScheme and provide the required properties (OAuth by default).
Specify the . If you have multiple companies in your organization, you must also specify the to indicate which company you would like to connect to. does not need to be specified if you have only one company.
To authenticate with an Access Key, set AuthScheme to "AccessKey" and provide the and properties.
To obtain the and values, navigate to the Users page in Dynamics 365 Business Central and then click on Edit. The User Name and Web Service Access Key values are what you will enter as the and connection string properties. Note that the User Name is not your email address. It is a shortened user name.
If you wish to authenticate through other methods, refer to the Help documentation.
For assistance in constructing the JDBC URL, use the connection string designer built into the Dynamics 365 Business Central JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.d365businesscentral.jar
Fill in the connection properties and copy the connection string to the clipboard.
👁 Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)A connection string for Dynamics 365 Business Central will typically look like the following:
jdbc:d365businesscentral:OrganizationUrl=https://myaccount.financials.dynamics.com/;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:d365businesscentral:OrganizationUrl=https://myaccount.financials.dynamics.com/;InitiateOAuth=GETANDREFRESH;");
MyAccountsDAO dao = dbi.open(MyAccountsDAO.class);
//do stuff with the DAO
dao.close();
With the connection open to Dynamics 365 Business Central, simply call the previously defined method to retrieve data from the Accounts entity in Dynamics 365 Business Central.
//disply the result of our 'find' method
String name = dao.findNameByName("MyAccount");
System.out.println(name);
It is also simple to write data to Dynamics 365 Business Central, using the previously defined method.
//add a new entry to the Accounts 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 Business Central by integrating with the CData JDBC Driver for Dynamics 365 Business Central. Download a free trial and work with live Dynamics 365 Business Central data in custom Java applications today.
Download a free trial of the Dynamics 365 Business Central Driver to get started:
Download NowLearn more:
👁 Dynamics 365 Business Central (NAV) IconRapidly create and deploy powerful Java applications that integrate with Dynamics 365 Business Central account data including Items, Sales Orders, Purchase Orders, and more!