Ready to get started?

Download a free trial of the MS Project Driver to get started:

 Download Now

Learn more:

Microsoft Project Icon MS Project JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Microsoft Project data including Tasks, Issues, Projects, Deliverables, and more!

Create a Data Access Object for Microsoft Project Data using JDBI



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

Create a DAO for the Microsoft Project Projects 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 MyProjectsDAO { //insert new data into Microsoft Project @SqlUpdate("INSERT INTO Projects (ProjectName, ProjectActualCost) values (:projectName, :projectActualCost)") void insert(@Bind("projectName") String projectName, @Bind("projectActualCost") String projectActualCost); //request specific data from Microsoft Project (String type is used for simplicity) @SqlQuery("SELECT ProjectActualCost FROM Projects WHERE ProjectName = :projectName") String findProjectActualCostByProjectName(@Bind("projectName") String projectName); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Microsoft Project

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

The User and Password properties, under the Authentication section, must be set to valid Microsoft Project user credentials. In addition, you will need to specify a URL to a valid Microsoft Project server organization root or Microsoft Project services file.

Built-in Connection String Designer

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

java -jar cdata.jdbc.microsoftproject.jar

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

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

jdbc:microsoftproject:User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;

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:microsoftproject:User=myuseraccount;Password=mypassword;URL=http://myserver/myOrgRoot;"); MyProjectsDAO dao = dbi.open(MyProjectsDAO.class); //do stuff with the DAO dao.close();

Read Microsoft Project Data

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

//disply the result of our 'find' method String projectActualCost = dao.findProjectActualCostByProjectName("Tax Checker"); System.out.println(projectActualCost);

Write Microsoft Project Data

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

//add a new entry to the Projects entity dao.insert(newProjectName, newProjectActualCost);

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