![]() |
VOOZH | about |
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.
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
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.
Set to OAuth.
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:
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:
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");
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.
Download a free trial of the Salesforce Data Cloud Driver to get started:
Download NowLearn more:
👁 Salesforce Data Cloud IconRapidly create and deploy powerful Java applications that integrate with Salesforce Data Cloud.