Model Context Protocol (MCP) finally gives AI models a way to access the business data needed to make them really useful at work. CData MCP Servers have the depth and performance to make sure AI has access to all of the answers.
Try them now for free →Connect to Salesforce Data Cloud Data from a Connection Pool in Jetty
The Salesforce Data Cloud JDBC Driver supports connection pooling: This article shows how to connect faster to Salesforce Data Cloud data from Web apps in Jetty.
The CData JDBC driver for Salesforce Data Cloud is easy to integrate with Java Web applications. This article shows how to efficiently connect to Salesforce Data Cloud data in Jetty by configuring the driver for connection pooling. You will configure a JNDI resource for Salesforce Data Cloud in Jetty.
Configure the JDBC Driver for Salesforce as a JNDI Data Source
Follow the steps below to connect to Salesforce from Jetty.
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
- Add the CData and license file, located in the lib subfolder of the installation directory, into the lib subfolder of the context path.
-
Declare the resource and its scope. Enter the required connection properties in the resource declaration. This example declares the Salesforce Data Cloud data source at the level of the Web app, in WEB-INF\jetty-env.xml.
<Configure id='salesforcedcdemo' class="org.eclipse.jetty.webapp.WebAppContext"> <New id="salesforcedcdemo" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg><Ref refid="salesforcedcdemo"/></Arg> <Arg>jdbc/salesforcedcdb</Arg> <Arg> <New class="cdata.jdbc.salesforcedatacloud.SalesforceDataCloudDriver"> <Set name="url">jdbc:salesforcedatacloud:</Set> <Set name="InitiateOAuth">GETANDREFRESH</Set> </New> </Arg> </New> </Configure>
Salesforce Data Cloud supports authentication via the OAuth standard.
OAuth
Set AuthScheme to OAuth.
Desktop Applications
CData provides an embedded OAuth application that simplifies authentication at the desktop.
You can also authenticate from the desktop via a custom OAuth application, which you configure and register at the Salesforce Data Cloud console. For further information, see Creating a Custom OAuth App in the Help documentation.
Before you connect, set these properties:
- InitiateOAuth: GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- OAuthClientId (custom applications only): The Client ID assigned when you registered your custom OAuth application.
- OAuthClientSecret (custom applications only): The Client Secret assigned when you registered your custom OAuth application.
When you connect, the driver opens Salesforce Data Cloud's OAuth endpoint in your default browser. Log in and grant permissions to the application.
The driver then completes the OAuth process as follows:
- Extracts the access token from the callback URL.
- Obtains a new access token when the old one expires.
- Saves OAuth values in OAuthSettingsLocation so that they persist across connections.
For other OAuth methods, including Web Applications and Headless Machines, refer to the Help documentation.
-
Configure the resource in the Web.xml:
jdbc/salesforcedcdb javax.sql.DataSource Container -
You can then access Salesforce Data Cloud with a lookup to java:comp/env/jdbc/salesforcedcdb:
InitialContext ctx = new InitialContext(); DataSource mysalesforcedc = (DataSource)ctx.lookup("java:comp/env/jdbc/salesforcedcdb");
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.