Connecting to External Databases
You may want to connect to a database in your workflow function scripts, for instance read data from an external source in a validator.
The easiest method is to use groovy sql. But, there is a gotcha or two.
JDBC drivers must be loaded by the system classloader, and furthermore the DriverManager will make checks that the driver class is accessible from the classloader of the calling class. In an OSGi environment this causes problems.
So, the following code will not work:
import groovy.sql.Sql Sql.newInstance("jdbc:postgresql://localhost:5432/jira_62", "jiradb", "")
you will get an error: No suitable driver found for jdbc:postgresql://localhost:5432/jira_62
Instead, manually load the driver class and create the connection:
Driver jar files should be placed in your tomcat/lib directory, eg <jira.install>/lib, but Jira already ships with the major drivers.
Querying the Current Jira Database
You can execute a query against the current Jira database, for instance in reports. Here’s how:
Direct database update queries are not recommended in Jira. Instead, we recommend adding or modifying data using Jira’s APIs (via ScriptRunner). If you absolutely must modify data in your database via direct database queries, always back up your data before performing any modification to the database.