On this page
Overview
SQL Macros such as SQL, SQL-query, and SQL-file use Data Sources to connect and access your databases. Creating one or more Data Source Profiles is the fastest and most convenient method of establishing a connection. You can also create Data Source Profiles that extend Data Sources configured within your application server.
Note: You must have at least one Data Source in order to begin using this application within Confluence.
Add Data Source Profiles
To add new or extend an existing Data Source Profile:
- Log in as a user with the Confluence Administrators Global Permission.
- Select Add-ons from the Administration menu (cog icon: ) at the top right of your screen. Then scroll down to Bob Swift Configuration on the sidebar and select SQL Configuration (see: ).
- Select View and Modify Data Source Profiles (see: ) from the top navigation.
- Click the button.
Setup Options
The Add Profile screen will provide you with two setup options:
- Simple - this is the most straightforward way to connect to your database.
- By connection string - use this option if you want to specify additional parameters and are comfortable constructing a database URL.
Depending on the setup type, you'll be prompted for the following information.
Setup type | Field | Description |
---|---|---|
Simple | Database type | The type of database you are connecting to. |
Simple | Data source name | You have the option to create a new Data Source Profile by extending an existing Data Source. This may be useful if you'd like to tighten/alter the configuration parameter settings to be more/less restrictive for certain usage. You can of course then secure the usage using our Macro Security for Confluence App. |
Simple | Hostname | This is the hostname or IP address of your database server. |
Simple | Port | This is the port used to access your database on the server it is running against. |
Simple | Database | This is the name of your database. |
Both | Driver class | The class of JDBC driver that you will use to connect to your database (e.g., com.mysql.jdbc.Driver, or org.postgresql.Driver) |
Both | Driver JAR location | The path on your Confluence server where the JDBC driver is located. Start with an absolute file reference Usually better to start with an absolute reference to make sure it is working. Relative references are more maintainable, but can be problematic especially on Windows. After it is working, you can experiment with relative references. |
By connection string | Connection string | The database URL is entered in this format (SQLServer example): jdbc:sqlserver://<hostname>:<port>;database=<database> For example: Once you select the By connection string option and start filling in the details of the Connection string field, the Simple (recommended) Setup type is disabled (for you to switch to Simple). If you want to switch to Simple, it is enabled only when you empty the details in the Connection string field. |
Both | Username | This is the username of your dedicated database user. |
Both | Password | This is the password for your dedicated database user. |
Quick Connection Strings
When using the "By connection string" setup option the following examples can be quickly copied into the relevant sections and then modified:
The configuration for other databases is similar to the information found in the examples section on: Data source configuration - application server.
Database | Example |
---|---|
PostgreSQL | dbUrl=jdbc:postgresql://localhost:5432/test | dbUser=confluence | dbPassword=confluence | dbDriver=org.postgresql.Driver | dbJar=https://jdbc.postgresql.org/download/postgresql-9.3-1102.jdbc41.jar |
PostgreSQL (using specific Schema) | dbUrl=jdbc:postgresql://localhost:5432/test?currentSchema=jiraschema | dbUser=confluence | dbPassword=confluence | dbDriver=org.postgresql.Driver | dbJar=https://jdbc.postgresql.org/download/postgresql-9.3-1102.jdbc41.jar |
MySQL | dbUrl=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true | dbUser=confluence | dbPassword=confluence | dbDriver=com.mysql.jdbc.Driver | dbJar=http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar |
Microsoft SQL Server | dbDriver=com.microsoft.sqlserver.jdbc.SQLServerDriver | dbUrl=jdbc:sqlserver://localhost:2433;database=test;integratedSecurity=false | dbUser=confluence | dbPassword=confluence | dbJar=../lib/sqljdbc4.jar |
Extended Parameters
Data Source Profiles allow for the configuration of extended parameter options. These profile-wide settings will be used by all SQL Macros if not overridden at the Macro-level.
Table: extended parameter options explained
Parameter | Macro Parameter | Default | Description |
---|---|---|---|
Limit rows processed | limit | No limit | The maximum number of rows that will be processed and displayed by SQL macros. This prevents queries that result in a large number of rows from using excessive resources. Individual queries can use the limit parameter to override this value. The following options are available for selection:
|
Limit query time | queryTimeout | None | The number of seconds that a query can take before we force a timeout. This prevents queries that take too long from impacting other users. Individual queries can use the queryTimeout parameter to override this value. Note, this parameter:
|
Limit max active | maxActive | None | Used to limit the number of actively executing SQL queries for a specific data source. Once the maximum active limit is reached, the next requested render of a sql macro using the specific data source will return an error message instead of trying to connect to the database. See this article for additional information. |
Show sql options | showSqlOptions | None | Since 6.4. A comma separated list of code or code-pro (Code Pro Macro) parameters used when Show SQL is selected. This allows for customization of how the SQL code is shown. See How to improve the display of SQL source. |
Connection properties | connectionProperties | None | A list of driver specific properties passed to the driver for creating connections. Each property is given as name=value , multiple properties are separated by semicolons (; ). See Apache Tomcat JNDI resources. |
Initial SQLs | initalSql<n> | None | SQL that is run after the SQL connection is established where n is a number (1, 2, 3, ...). Multiple initial SQL statements are allowed to support databases that only allow single SQL statements. Example use for Oracle: initialSql1=ALTER SESSION SET NLS_TERRITORY = GERMANY|initialSql2=ALTER SESSION SET NLS_LANGUAGE = GERMAN No results are kept and any errors will generate a macro exception. Using beforeSql is recommended for Postgres and other database that support multiple sql statements as it is more efficient than multiple separated actions. |
Before SQL | beforeSql | None | SQL that is added before Macro defined SQL. |
After SQL | afterSql | None | SQL that is added after Macro defined SQL. |
View Data Source Profiles
To view a Data Source Profile:
- Log in as a user with the Confluence Administrators Global Permission.
- Select Add-ons from the Administration menu (cog icon: ) at the top right of your screen. Then scroll down to Bob Swift Configuration on the sidebar and select SQL Configuration (see: ).
- Select View and Modify Data Source Profiles (see: ) from the top navigation.
- You will see a list of Data Source Profiles and their connection status.
Table: Status indicators explained
Indicator | Definition |
---|---|
Indicates that the connection information supplied for the Data Source Profile will allow connections from Confluence to the targeted database. This does not indicate that the Data Source Profile is in use by any Macros on Confluence pages. | |
Indicates that your connection-specific information is incorrect. See Troubleshooting Data Source Profile connections. |
Modify Data Source Profiles
To modify a Data Source Profile:
- Log in as a user with the Confluence Administrators Global Permission.
- Select Add-ons from the Administration menu (cog icon: ) at the top right of your screen. Then scroll down to Bob Swift Configuration on the sidebar and select SQL Configuration (see: ).
- Select View and Modify Data Source Profiles (see: ) from the top navigation.
- You will see a list of Data Source Profiles and their connection status.
- Click the edit link to the right of the Data Source Profile you would like to modify.
- The edit dialog will appear and will default to the "By connection string" view. You can edit in place or toggle to the "Simple" setup type and make necessary changes.
- To save changes, click the Next button (see: ) and then the Save Profile (see: ) button.
Remove Data Source Profiles
Removing Data Source Profiles extended by SQL Macros will render the Macro and section of the page broken.
To remove a Data Source Profile:
- Log in as a user with the Confluence Administrators Global Permission.
- Select Add-ons from the Administration menu (cog icon: ) at the top right of your screen. Then scroll down to Bob Swift Configuration on the sidebar and select SQL Configuration (see: ).
- Select View and Modify Data Source Profiles (see: ) from the top navigation. You see a list of Data Source Profiles and their connection status.
- Click the remove link to the right of the Data Source Profile you would like to remove.
- When prompted, confirm or exit.
Test a Data Source Profile
To test one or more Data Source Profiles:
- Create a new page or edit an existing.
- Select Insert Markup from menu (icon: ) on the top nav.
Within the dialog window add the following wiki markup and make sure to change the dataSource to a Data Source Profile that you have created.
{sql-query:dataSource=example} select "This is working" {sql-query}
- Click Insert and then save the page.
If successful, the following is rendered on the page
Next Steps: Get to work
You've configured the product, you understand the differences between Data Sources and Data Source Profiles, and you likely have a few configured. You are now ready to start using SQL Macros within Confluence pages.