Connecting from Code
This section describes how to connect with the JDBC DriverManager or ReckonAccountsHostedDataSource interfaces.
Connecting with the DriverManager
When connecting with the DriverManager class, the CData JDBC Driver for Reckon Accounts Hosted follows the JDBC convention: First, load the ReckonAccountsHosted driver class. Then, make a connection.
Load the Driver
The following step is optional per the JDBC 4.0 specification.Class.forName("cdata.jdbc.reckonaccountshosted.ReckonAccountsHostedDriver");
Establish a Connection
Provide the connection string with the getConnection method of the static DriverManager class. Start the connection string with "jdbc:reckonaccountshosted:". A typical connection string is the following:
Connection conn = DriverManager.getConnection("jdbc:reckonaccountshosted:SubscriptionKey=test;CountryVersion=2021.R2.AU;CompanyFile=Q:/CData Software.QBW;User=test;Password=test;InitiateOAuth=GETANDREFRESH;CallbackURL=http://localhost:33333;OAuthClientId=MyOAuthClientID;OAuthClientSecret=MyOAuthClientSecret;");Alternatively, you can prepare the connection options using a Properties object. Pass the Properties object to the DriverManager.
prop.setProperty("SubscriptionKey","test"); prop.setProperty("CountryVersion","2021.R2.AU"); prop.setProperty("CompanyFile","Q:/CData Software.QBW"); prop.setProperty("User","test"); prop.setProperty("Password","test"); prop.setProperty("InitiateOAuth","GETANDREFRESH"); prop.setProperty("CallbackURL","http://localhost:33333"); prop.setProperty("OAuthClientId","MyOAuthClientID"); prop.setProperty("OAuthClientSecret","MyOAuthClientSecret"); Connection conn = DriverManager.getConnection("jdbc:reckonaccountshosted:",prop);
Connecting with the ReckonAccountsHostedDataSource Class
You can use the ReckonAccountsHostedDataSource 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:
ReckonAccountsHostedDataSource ds = new ReckonAccountsHostedDataSource("jdbc:reckonaccountshosted:UseConnectionPooling=true;SubscriptionKey=test;CountryVersion=2021.R2.AU;CompanyFile=Q:/CData Software.QBW;User=test;Password=test;InitiateOAuth=GETANDREFRESH;CallbackURL=http://localhost:33333;OAuthClientId=MyOAuthClientID;OAuthClientSecret=MyOAuthClientSecret;");
Connection conn = ds.getConnection();