H2 database using groovy from scriptrunner

manjunath August 8, 2016

Was able to get past the connection using groovy script in scriptrunner, however the query is saying the table does not exists, it says JIRAISSUE not found.

 

Could somebody please help on this?

 

 

import groovy.sql.Sql
import java.sql.Driver
def driver = Class.forName('org.h2.Driver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "sa")
props.setProperty("password", "")
def conn = driver.connect("jdbc:h2:~/test", props)
def sql = new Sql(conn)
try {
sql.eachRow("SELECT COUNT(*) FROM JIRAISSUE")
{ log.debug(it) }
} finally {
sql.close()
conn.close()
}

 

 

3 answers

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 9, 2016

Why don't you have a look at the db - https://confluence.atlassian.com/jirakb/accessing-jira-s-h2-embedded-database-776818136.html

Perhaps the case is wrong or you need to prefix with the schema.

0 votes
manjunath August 9, 2016

Thanks Nic.

 

Currently i am doing an POC on JIRA and one of the action item is to pick the values from specific table from external DB (oracle or SQL) and populate in  JIRA custom field.

As of now, i dont have acess to these DB's and want to show this to my leaders that  this can be achieved from 

scriptrunner.

 

Any help on this will be greatly appreciated.

Thanks

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 9, 2016

Ok, I would stay well away from the JIRA database when doing this.  You really need to use the API to do the population of the fields (you can't do it with database access). 

In this case, I would set up a new, empty database server (a simple Postgres or MySQL database server running locally) and set up your code to show you can read tables from that and use the API to do things with the read data in JIRA.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 9, 2016

I'd strongly recommend NOT trying to do this.  The H2 database is not a system you should be using in production, so your work is pretty much pointless anyway, and, more importantly, your approach is incorrect - you should not be trying to read the database.

If you need to know how many issues there are in a JIRA in a script, use the system information api, or run a blank JQL query and ask the result for .size.  Both those methods are database agnostic, faster and don't risk inaccuracy or damage.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events