import groovy.sql.Sql; import groovy.sql.GroovyRowResult; import java.sql.SQLException; Sql connection; String dbConnection = "jdbc:mysql://localhost:3306/jiradb?useUnicode=true&characterEncoding=UTF8&sessionVariables=storage_engine=InnoDB"; String dbDriver = "com.mysql.jdbc.Driver"; String dbUserid = "jiradbuser"; String dbPasswd = "JiraDBUser"; String quoteTable = "cost_of_repair_c10809"; try { connection = Sql.newInstance( dbConnection, dbUserid, dbPasswd, dbDriver ); } catch (SQLException e) { return "Unknown (Issue connecting to the database: ${e.getMessage()})"; } GroovyRowResult result = null; try { log.debug("issue = ${issue.id}"); result = connection.firstRow("select sum(amount) subtotal from " + quoteTable + " where issueId = " + issue.id); } catch (SQLException e) { log.debug ("Issue retrieving data from the database: " + e.getMessage()) return 0D; } if (result == null) { // no value given return 0D; } return result.get("subtotal");