Display SQL Results from an External Database Macro

If you want to display SQL results from an external database in a table, you can easily accomplish this with a custom script macro. In this example, we display results from a pet store database:

sql table macro

To display results from an external database of your choice, first, you’ll create a Resource to configure an external database connection. See External Database Connection for more information.

Once you’ve created a Resource for your database connection, you can configure your custom script macro. The following image shows a sample configuration for this custom script macro:

sql table macro config

The file in the Macro Script field contains the following script:

Include Bitbucket for Confluence: File content cannot be shown

Unauthenticated access to this resource is not allowed. Please login to Confluence first.

Line 4You will replace 'petstore' with whatever you named your pool when configuring your Resource.

Line 9Notice our use of Groovy’s MarkupBuilder here. This is a helper class for creating XML or HTML markup. It’s very important to use the MarkupBuilder here to ensure your HTML is safe.