Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I connect to the Jira database inside a a Java program?

gfinesch July 31, 2018

Hi everyone,

we are uprgrading soon to the lastest Jira version. For this reason we're also adapting a few Java plugins we developed for Jira 6.x.

One of those plugins required importing 3 external tables into the Jira database and I need to query them via SQL. In the current version of my plugin, I create a java.sql.Connection in this way:

    protected static Connection getDatabaseConnection() {
        try {
            GenericHelper helper = CoreFactory.getGenericDelegator().getEntityHelper("User");
            DatabaseUtil utils = new DatabaseUtil(helper.getHelperName());

            return utils.getConnection();

        } catch (SQLException e) {
            throw new DataAccessException("Unable to obtain a DB connection", e);

        } catch (GenericEntityException e) {
            throw new DataAccessException("Unable to obtain a DB connection", e);
        }
    }

and then use the prepareStatement() method on what it returns. Unfortunately, CoreFactory.getGenericDelegator() is now deprecated. What replaces it? How can I achieve the same goal in another way? Any hints?

Thank you.

2 answers

0 votes
gfinesch August 1, 2018

I eventually used

            final OfBizConnectionFactory connectionFactory = new DefaultOfBizConnectionFactory();
            return connectionFactory.getConnection();

to get a java.sql.Connection object, hopefully it works the same way

0 votes
Mark Markov
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.
July 31, 2018

Suggest an answer

Log in or Sign up to answer