![]() |
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 PayPal integrates connectivity to live PayPal data in Java applications. By pairing these technologies, you gain simple, programmatic access to PayPal data. This article explains how to build a basic Data Access Object (DAO) and the accompanying code to read PayPal 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 MyTransactionsDAO {
//request specific data from PayPal (String type is used for simplicity)
@SqlQuery("SELECT GrossAmount FROM Transactions WHERE TransactionClass = :transactionClass")
String findGrossAmountByTransactionClass(@Bind("transactionClass") String transactionClass);
/*
* 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 PayPal.
The provider surfaces tables from two PayPal APIs. The APIs use different authentication methods.
See the "Getting Started" chapter of the help documentation for a guide to obtaining the necessary API credentials.
To select the API you want to work with, you can set the Schema property to REST or SOAP. By default the SOAP schema will be used.
For testing purposes you can set UseSandbox to true and use sandbox credentials.
For assistance in constructing the JDBC URL, use the connection string designer built into the PayPal JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.paypal.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 PayPal will typically look like the following:
jdbc:paypal:Schema=SOAP;Username=sandbox-facilitator_api1.test.com;Password=xyz123;Signature=zx2127;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:paypal:Schema=SOAP;Username=sandbox-facilitator_api1.test.com;Password=xyz123;Signature=zx2127;InitiateOAuth=GETANDREFRESH;");
MyTransactionsDAO dao = dbi.open(MyTransactionsDAO.class);
//do stuff with the DAO
dao.close();
With the connection open to PayPal, simply call the previously defined method to retrieve data from the Transactions entity in PayPal.
//disply the result of our 'find' method
String grossAmount = dao.findGrossAmountByTransactionClass("Received");
System.out.println(grossAmount);
Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for PayPal by integrating with the CData JDBC Driver for PayPal. Download a free trial and work with live PayPal data in custom Java applications today.
Download a free trial of the PayPal Driver to get started:
Download NowLearn more:
👁 PayPal IconEasy-to-use PayPal client enables Java-based applications to easily consume PayPal Transactions, Orders, Sales, Invoices, etc.