Connect to Xero Data from a Connection Pool in Jetty

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Xero JDBC Driver

Complete read-write access to Xero accounting enables developers to search (Customers, Transactions, Invoices, Sales Receipts, etc.), update items, edit customers, and more, from any Java/J2EE application.



The Xero JDBC Driver supports connection pooling: This article shows how to connect faster to Xero data from Web apps in Jetty.

The CData JDBC driver for Xero is easy to integrate with Java Web applications. This article shows how to efficiently connect to Xero data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for Xero in Jetty.

Configure the JDBC Driver for Salesforce as a JNDI Data Source

Follow the steps below to connect to Salesforce from Jetty.

  1. Enable the JNDI module for your Jetty base. The following command enables JNDI from the command-line:

    java -jar ../start.jar --add-to-startd=jndi
  2. Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
  3. Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the Xero data source at the level of the Web app, in WEB-INF\jetty-env.xml.

    <Configure id='xerodemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="xerodemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="xerodemo"/></Arg> <Arg>jdbc/xerodb</Arg> <Arg> <New class="cdata.jdbc.xero.XeroDriver"> <Set name="url">jdbc:xero:</Set> <Set name="InitiateOAuth">GETANDREFRESH</Set> </New> </Arg> </New> </Configure>

    To connect, set the Schema connection property in addition to any authentication values. Xero offers authentication for private applications, public applications, and partner applications. You will need to set the XeroAppAuthentication property to PUBLIC, PRIVATE, or PARTNER, depending on the type of application configured. To connect from a private application, you will additionally need to set the OAuthAccessToken, OAuthClientId, OAuthClientSecret, CertificateStoreType, CertificateStore, and CertificateStorePassword.

    To connect from a public or partner application, you can use the embedded OAuthClientId, OAuthClientSecret, and CallbackURL, or you can register an app to obtain your own OAuth values.

    See the "Getting Started" chapter of the help documentation for a guide to authenticating to Xero.

  4. Configure the resource in the Web.xml:

    jdbc/xerodb javax.sql.DataSource Container
  5. You can then access Xero with a lookup to java:comp/env/jdbc/xerodb: InitialContext ctx = new InitialContext(); DataSource myxero = (DataSource)ctx.lookup("java:comp/env/jdbc/xerodb");

More Jetty Integration

The steps above show how to configure the driver in a simple connection pooling scenario. For more use cases and information, see the Working with Jetty JNDI chapter in the Jetty documentation.