Create a Data Access Object for Microsoft Teams Data using JDBI



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

Create a DAO for the Microsoft Teams Teams 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 MyTeamsDAO { //insert new data into Microsoft Teams @SqlUpdate("INSERT INTO Teams (Id, location_displayName) values (:id, :location_displayName)") void insert(@Bind("id") String id, @Bind("location_displayName") String location_displayName); //request specific data from Microsoft Teams (String type is used for simplicity) @SqlQuery("SELECT location_displayName FROM Teams WHERE Id = :id") String findlocation_displayNameById(@Bind("id") String id); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Microsoft Teams

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

You can connect to MS Teams using the embedded OAuth connectivity. When you connect, the MS Teams OAuth endpoint opens in your browser. Log in and grant permissions to complete the OAuth process. See the OAuth section in the online Help documentation for more information on other OAuth authentication flows.

Built-in Connection String Designer

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

java -jar cdata.jdbc.msteams.jar

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

A connection string for Microsoft Teams will typically look like the following:

jdbc:msteams:OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;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:msteams:OAuthClientId=MyApplicationId;OAuthClientSecret=MySecretKey;CallbackURL=http://localhost:33333;InitiateOAuth=GETANDREFRESH"); MyTeamsDAO dao = dbi.open(MyTeamsDAO.class); //do stuff with the DAO dao.close();

Read Microsoft Teams Data

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

//disply the result of our 'find' method String location_displayName = dao.findlocation_displayNameById("Jq74mCczmFXk1tC10GB"); System.out.println(location_displayName);

Write Microsoft Teams Data

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

//add a new entry to the Teams entity dao.insert(newId, newlocation_displayName);

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

Ready to get started?

Download a free trial of the Microsoft Teams Driver to get started:

 Download Now

Learn more:

Microsoft Teams Icon Microsoft Teams JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Microsoft Teams.