Ready to get started?

Learn more about the CData JDBC Driver for MYOB AccountRight or download a free trial:

Download Now

Query MYOB AccountRight Data in ColdFusion

Write standard ColdFusion data access code to connect to MYOB AccountRight data.

The CData JDBC Driver for MYOB AccountRight seamlessly integrates connectivity to MYOB AccountRight data with the rapid development tools in ColdFusion. This article shows how to connect to MYOB AccountRight data in ColdFusion and query MYOB AccountRight tables.

Create a JDBC Data Source for MYOB AccountRight in ColdFusion

The JDBC data source enables you to execute SQL from standard ColdFusion tags like cfquery and CFScript like executeQuery.

  1. Copy the driver JAR and .lic file from the installation directory onto the ColdFusion classpath. For example, copy the files into C:\MyColdFusionDirectory\cfusion\wwwroot\WEB-INF\lib. Or, open the Java and JVM page in the ColdFusion Administrator and enter the path to the files in the ColdFusion Class Path box.

    The JAR and license for the driver are located in the lib subfolder of the installation directory.

    Restart the server after this step.

  2. Add the driver as a data source:

    From the ColdFusion administrator interface, expand the Data & Services node and click Data Sources. In the Add New Data Source section, enter a name for the data source and select Other in the Driver menu.

  3. Populate the driver properties:

    • JDBC URL: Enter connection properties in the JDBC URL. The JDBC URL begins with jdbc:myob: and is followed by the connection properties in a semicolon-separated list of name=value pairs.

      These properties are required when connecting to a company file (both for Cloud and On-Premise instances).

      • CompanyFileId: You can find this by starting MYOB, opening your data file, and selecting Help -> About MYOB
      • User: The username associated with your company file.
      • Password: The password associated with your company file.

      Connecting to a Cloud Instance

      To connect to a cloud instance of MYOB, you can use the embedded OAuth credentials or create an OAuth app with MYOB. This process is detailed in the Help documentation.

      Connecting to an On-Premise instance:

      When connecting to an on-premise instance, you will need to set the following connection property in addition to those above:

      • InitiateOauth: Set this to OFF.
      • Url: The Url of your MYOB instance.

      Built-in Connection String Designer

      For assistance in constructing the JDBC URL, use the connection string designer built into the MYOB AccountRight JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

      java -jar cdata.jdbc.myob.jar

      Fill in the connection properties and copy the connection string to the clipboard.

      A typical JDBC URL is below:

      jdbc:myob:OAuthClientId=YourClientId; OAuthClientSecret=YourClientSecret; CompanyFileId=yourCompanyFileId; CallbackURL=http://localhost:33333; User=companyFileUser; Password=companyFilePassword; InitiateOAuth=GETANDREFRESH
    • Driver Class: Enter the driver class. The driver class is cdata.jdbc.myob.MYOBDriver.
    • Driver Name: Enter a user-defined name for the driver.
    • Username: Enter the username used to authenticate.
    • Password: Enter the password used to authenticate.

You can now test the connection by enabling the CData MYOB AccountRight data source in the Actions column. After reporting a status of OK, the MYOB AccountRight data source is ready for use.

Execute Queries

The cfquery tag can pass SQL statements to MYOB AccountRight, including INSERT, UPDATE, and DELETE.. Use the cfqueryparam tag to create parameterized queries and prevent SQL injection through the query string.

<cfquery name="MYOBQuery" dataSource="CDataMYOB"> SELECT * FROM Accounts WHERE Type = <cfqueryparam value="#Type#" cfsqltype="cf_sql_varchar"> </cfquery> <cfdump var="#MYOBQuery#">

Below is the equivalent in CFScript:


<cfscript>
result = queryExecute(
  "SELECT * FROM Accounts WHERE Type = ?", 
  [
    { value="Bank", cfsqltype="cf_sql_varchar" }
  ],
  { datasource="CDataMYOB" }
);

writeDump( var= result );
</cfscript> 

You can then make requests to your .cfm like the following:

http://MyServer:8500/query.cfm?Type=Bank