Connect to Short.io Data from PowerBuilder via JDBC
The CData JDBC driver for Short.io is a standards-based control that can be used from any platform or development technology that supports JDBC, including PowerBuilder. This article shows how to use the CData JDBC Driver for Short.io in PowerBuilder.
This article shows how to create a basic PowerBuilder application that uses the CData JDBC Driver for Short.io to retrieve data.
Connect to Short.io Data from PowerBuilder
Follow the steps below to use the Database Painter tool to create a database profile based on an JDBC URL for Short.io. You can use a database profile to save connection properties. In the Database Painter, you can graphically manipulate data as well as execute SQL queries.
Add the driver JAR to the PowerBuilder classpath. Set the CLASSPATH system environment variable to the path to the driver JAR, located in the lib subfolder of the installation directory.
Note: If you are using PowerBuilder Classic, you can also add the path to the driver JAR by clicking Tools -> System Options -> Java.
- Click Tools -> Database Painter.
- Right-click the JDBC node and click New Profile.
- In the Database Profile Setup dialog, enter the following:
- Profile Name: Enter a user-friendly name for the profile.
- Driver Name: Enter the class name of the driver, cdata.jdbc.api.APIDriver
- URL: Enter the JDBC URL.
Using API Key Authentication
Short.io uses API Key authentication. To obtain your API key:
- Log in to your Short.io account
- Navigate to Settings > Integrations & API > API
- Click Create API Key and copy your API key
After obtaining the API key, you are ready to connect:
- AuthScheme: Set this to APIKey.
- APIKey: Set this to your Short.io API key obtained from Settings > Integrations & API > API.
Example connection string:
Profile=C:\profiles\ShortIo.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key';
Available Tables
The Short.io profile provides access to the following tables:
- Domains - Short.io domains associated with the authenticated account
- Links - Short links for a domain
- LinkExpand - Expand a short link by domain and path
- LinksByOriginalUrl - Retrieve multiple short links matching a given original destination URL
- Folders - Link folders within a specific domain
- LinkPermissions - Permission records for a specific link within a domain
- CountryTargeting - Country-based redirect targeting rules for a specific short link
- RegionTargeting - Region-based redirect targeting rules for a specific short link
- Regions - List of available regions/states for a given country code
- DomainStatistics - Aggregated click and traffic statistics for a Short.io domain
- LinkStatistics - Aggregated click and traffic statistics for a specific Short.io link
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Short.io JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.api.jar
Fill in the connection properties and copy the connection string to the clipboard. A typical JDBC URL is below:
jdbc:api:Profile=C:\profiles\ShortIo.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key';
- To view and modify a table, right-click a table and then click Edit Data -> Grid.
Using Short.io Data with PowerBuilder Controls
You can use standard PowerBuilder objects to connect to JDBC data sources and execute queries. The following example shows how to retrieve Short.io data into a DataWindow. You can add the following code to the open method:
SQLCA.DBMS = "JDBC" SQLCA.AutoCommit = False SQLCA.DBParm = "Driver='cdata.jdbc.api.APIDriver',URL='jdbc:api:Profile=C:\profiles\ShortIo.apip;AuthScheme=APIKey;ProfileSettings='APIKey=your_api_key';"; CONNECT USING SQLCA; dw_domains.SetTransObject(SQLCA); dw_domains.Retrieve();