Ready to get started?

Learn more about the CData JDBC Driver for YouTube Analytics or download a free trial:

Download Now

Connect to YouTube Analytics Data from a Connection Pool in Jetty

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

The CData JDBC driver for YouTube Analytics is easy to integrate with Java Web applications. This article shows how to efficiently connect to YouTube Analytics data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for YouTube Analytics 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 YouTube Analytics data source at the level of the Web app, in WEB-INF\jetty-env.xml.

    <Configure id='youtubeanalyticsdemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="youtubeanalyticsdemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="youtubeanalyticsdemo"/></Arg> <Arg>jdbc/youtubeanalyticsdb</Arg> <Arg> <New class="cdata.jdbc.youtubeanalytics.YouTubeAnalyticsDriver"> <Set name="url">jdbc:youtubeanalytics:</Set> <Set name="ContentOwnerId">MyContentOwnerId</Set> <Set name="ChannelId">MyChannelId</Set> <Set name="InitiateOAuth">GETANDREFRESH</Set> </New> </Arg> </New> </Configure>

    YouTube Analytics uses the OAuth authentication standard. You can use the embedded CData OAuth credentials or you can register an application with Google to obtain your own.

    In addition to the OAuth values, to access YouTube Analytics data set ChannelId to the Id of a YouTube channel. You can obtain the channel Id in the advanced account settings for your channel. If not specified, the channel of the currently authenticated user will be used.

    If you want to generate content owner reports, specify the ContentOwnerId property. This is the Id of the copyright holder for content in YouTube's rights management system. The content owner is the person or organization that claims videos and sets their monetization policy.

  4. Configure the resource in the Web.xml:

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

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.