Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update on Oracle DB with MyGroovy script #60

Open
mlk87 opened this issue Feb 4, 2020 · 3 comments
Open

Update on Oracle DB with MyGroovy script #60

mlk87 opened this issue Feb 4, 2020 · 3 comments

Comments

@mlk87
Copy link

mlk87 commented Feb 4, 2020

Good morning,
I'm trying to create a script to be able to perform updates on the Oracle DB, but currently it doesn't work.
At the moment it works perfectly in reading.
The script for reading is as follows:

import groovy.sql.Sql
import java.sql.Driver

def driver = Class.forName('oracle.jdbc.OracleDriver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "USER") 
props.setProperty("password", "PWD")
def conn = driver.connect("jdbc:oracle:thin:@SERVER:PORT:ISTANCE", props) 
def sql = new Sql(conn)
def results = sql.rows("MY QUERY")
return results

In update I replaced sql.rows with sql.execute, but to no avail:

sql.execute "MY UPDATE QUERY"

can you help me?

@ItaloQualisoni
Copy link

Did you include Oracle JDBC driver in /lib folder?
See step 2 of this documentation that describe how to do it, you will need to restart JIRA in order to the changes be applied.

Also, what is the output of your script? Can you attach a screenshot?

@mlk87
Copy link
Author

mlk87 commented Feb 10, 2020

The driver is correct, in reading with the SELECT I can get the result.
Testing the script on the MyGroovy console, but it returns a generic error

import groovy.sql.Sql
import java.sql.Driver

def driver = Class.forName('oracle.jdbc.OracleDriver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "USER") 
props.setProperty("password", "PWD")
def conn = driver.connect("jdbc:oracle:thin:@SERVER:PORT:ISTANCE", props) 
def sql = new Sql(conn)
def results = sql.executeUpdate("MY UPDATE QUERY")
return results

The result is: null and the log is not compiled

Screenshot

@lexek
Copy link

lexek commented Feb 13, 2020

Hi, can you check Jira log for error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants