H2 database using groovy from scriptrunner

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 vote

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.

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

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 vote

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.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

863 views 2 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you