atlascommunity / jira-plugins-groovy

Jira Groovy plugin
https://atlasteam.ru
BSD 2-Clause "Simplified" License
66 stars 42 forks source link

Update on Oracle DB with MyGroovy script #60

Open mlk87 opened 4 years ago

mlk87 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Hi, can you check Jira log for error?