Connecting from Code
This section describes how to connect with the JDBC DriverManager or SageX3CloudDataSource interfaces.
Connecting with the DriverManager
When connecting with the DriverManager class, the CData JDBC Driver for Sage X3 Cloud follows the JDBC convention: First, load the SageX3Cloud driver class. Then, make a connection.
Load the Driver
The following step is optional per the JDBC 4.0 specification.Class.forName("cdata.jdbc.sagex3cloud.SageX3CloudDriver");
Establish a Connection
Provide the connection string with the getConnection method of the static DriverManager class. Start the connection string with "jdbc:sagex3cloud:". A typical connection string is the following:
Connection conn = DriverManager.getConnection("jdbc:sagex3cloud:URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;");
Alternatively, you can prepare the connection options using a Properties object. Pass the Properties object to the DriverManager.
Properties prop = new Properties();
prop.setProperty("URL","https://x3server/");
prop.setProperty("OAuthAccessTokenUrl","https://auth-domain/oauth/token");
prop.setProperty("OAuthClientId","your_client_id");
prop.setProperty("OAuthClientSecret","your_client_secret");
prop.setProperty("Audience","https://api-audience");
prop.setProperty("XAPIKey","your_api_key");
prop.setProperty("Folder","SEED");
Connection conn = DriverManager.getConnection("jdbc:sagex3cloud:",prop);
Connecting with the SageX3CloudDataSource Class
You can use the SageX3CloudDataSource class to create pooled connections, as shown in the following example. See Connection Pooling for more information.
The following example instantiates a pooled Connection object:
SageX3CloudDataSource ds = new SageX3CloudDataSource("jdbc:sagex3cloud:UseConnectionPooling=true;URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;");
Connection conn = ds.getConnection();