Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Create a Data Access Object for WooCommerce Data using JDBI
A brief overview of creating a SQL Object API for WooCommerce 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 WooCommerce integrates connectivity to live WooCommerce data in Java applications. By pairing these technologies, you gain simple, programmatic access to WooCommerce data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write WooCommerce data.
Create a DAO for the WooCommerce Orders 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 MyOrdersDAO {
//insert new data into WooCommerce
@SqlUpdate("INSERT INTO Orders (ParentId, Total) values (:parentId, :total)")
void insert(@Bind("parentId") String parentId, @Bind("total") String total);
//request specific data from WooCommerce (String type is used for simplicity)
@SqlQuery("SELECT Total FROM Orders WHERE ParentId = :parentId")
String findTotalByParentId(@Bind("parentId") String parentId);
/*
* close with no args is used to close the connection
*/
void close();
}
Open a Connection to WooCommerce
Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to WooCommerce.
WooCommerce supports the following authentication methods: one-legged OAuth1.0 Authentication and standard OAuth2.0 Authentication.
Connecting using one-legged OAuth 1.0 Authentication
Specify the following properties (NOTE: the below credentials are generated from WooCommerce settings page and should not be confused with the credentials generated by using WordPress OAuth2.0 plugin):
- ConsumerKey
- ConsumerSecret
Connecting using WordPress OAuth 2.0 Authentication