Ready to get started?

Download a free trial of the LinkedIn Driver to get started:

 Download Now

Learn more:

LinkedIn Icon LinkedIn JDBC Driver

A straightforward interface to connect any Java application with LinkedIn integration capabilities including People, Profiles, Companies, Groups, Jobs, and more!

Create a Data Access Object for LinkedIn Data using JDBI



A brief overview of creating a SQL Object API for LinkedIn 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 LinkedIn integrates connectivity to live LinkedIn data in Java applications. By pairing these technologies, you gain simple, programmatic access to LinkedIn data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write LinkedIn data.

Create a DAO for the LinkedIn CompanyStatusUpdates 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 MyCompanyStatusUpdatesDAO { //insert new data into LinkedIn @SqlUpdate("INSERT INTO CompanyStatusUpdates (EntityId, Comment) values (:entityId, :comment)") void insert(@Bind("entityId") String entityId, @Bind("comment") String comment); //request specific data from LinkedIn (String type is used for simplicity) @SqlQuery("SELECT Comment FROM CompanyStatusUpdates WHERE EntityId = :entityId") String findCommentByEntityId(@Bind("entityId") String entityId); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to LinkedIn

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to LinkedIn.

LinkedIn uses the OAuth 2 authentication standard. You will need to obtain the OAuthClientId and OAuthClientSecret by registering an app with LinkedIn. For more information refer to our authentication guide.

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the LinkedIn JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.linkedin.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for LinkedIn will typically look like the following:

jdbc:linkedin:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;CompanyId=XXXXXXXInitiateOAuth=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:linkedin:OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;CompanyId=XXXXXXXInitiateOAuth=GETANDREFRESH"); MyCompanyStatusUpdatesDAO dao = dbi.open(MyCompanyStatusUpdatesDAO.class); //do stuff with the DAO dao.close();

Read LinkedIn Data

With the connection open to LinkedIn, simply call the previously defined method to retrieve data from the CompanyStatusUpdates entity in LinkedIn.

//disply the result of our 'find' method String comment = dao.findCommentByEntityId("238"); System.out.println(comment);

Write LinkedIn Data

It is also simple to write data to LinkedIn, using the previously defined method.

//add a new entry to the CompanyStatusUpdates entity dao.insert(newEntityId, newComment);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for LinkedIn by integrating with the CData JDBC Driver for LinkedIn. Download a free trial and work with live LinkedIn data in custom Java applications today.