Forums

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

Not able to connect mysql db using scriptrunner

Vedant Kulkarni
Contributor
February 1, 2018

I want to connect to MySQL DB by using script runner. I applied behavior for this on a custom field. I paste the driver jar file in <jira-install>\lib and also studied this scriptrunner tutorial https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/connecting-to-databases.html . But I still getting this error. Am I doing it in right way?

script:-


def driver = Class.forName("com.mysql.cj.jdbc.Driver").newInstance() as Driver

def prop= new Properties()

prop.setProperty("user","admin")
prop.setProperty("password","123456780")

def conn=driver.connect("jdbc:mysql://localhost:3306/ISE_DB",prop)

def sql=new Sql(conn)

try {
sql.eachRow("select count(*) from Customer_View") {
log.debug(it)
}
} finally {
sql.close()
conn.close()
}

 

 

2018-02-01 12:17:45,242 http-nio-8080-exec-11 ERROR admin 737x410x2 73padh 0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: (create issue) project/issuetype: IFT/Task, user: admin, fieldId: customfield_10202, file: <inline script>
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver not found by com.onresolve.jira.groovy.groovyrunner [173]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at Script1.run(Script1.groovy:7)

2 answers

0 votes
MoroSystems Support
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.
February 2, 2018

I think that the result tab shows an output of the last command executed or last variable.

 

Maybe you are facing the same problem disscussed here https://community.atlassian.com/t5/Marketplace-Apps-questions/Groovy-script-accessing-MySQL-database-works-in-Script-Runner/qaq-p/364831

Vedant Kulkarni
Contributor
February 2, 2018

I already go through that problem but that doesn't solve it.

0 votes
MoroSystems Support
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.
February 1, 2018

Hello, 

are you sure, that you use proper class for MySql db driver. I usually use class 

com.mysql.jdbc.Driver when working with MySql database.

 

Regards,

Milos

Vedant Kulkarni
Contributor
February 1, 2018

I also tried that one but got the same error.

2018-02-01 12:15:41,277 http-nio-8080-exec-5 ERROR vedant 735x347x3 73padh 0:0:0:0:0:0:0:1 /rest/scriptrunner/behaviours/latest/runvalidator.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: (create issue) project/issuetype: IFT/Task, user: vedant, fieldId: customfield_10202, file: <inline script>
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found by com.onresolve.jira.groovy.groovyrunner [173]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
at Script1.run(Script1.groovy:7)

MoroSystems Support
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.
February 1, 2018

Could you provide link to your driver jar file? Where did you downloaded it?

And just to be sure - do you have all required imports in your groovy script as showed in the example from https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/connecting-to-databases.html ?

M.

Vedant Kulkarni
Contributor
February 2, 2018

as shown in screenshot I imported the required package.

This is link from which I downloaded the mysql driver

https://dev.mysql.com/downloads/connector/j/FieldTest.PNG

MoroSystems Support
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.
February 2, 2018

uuuh, I am lost :(

The drive file mysql-connector-java-5.1.45-bin.jar looks perfectly fine. It contains com.mysqljdbc.Driver class.

Did you try tu run the script in the Script Runner console? The same error?

What is a version of Jira you are using?

Vedant Kulkarni
Contributor
February 2, 2018

Yes, the script is running on console with desired output but it's not running when I tried to run through behaviors 

FieldTest1.PNGFieldTest2.PNG

in the logs, I am getting output but in the result tab, I am not getting output. Do I need to write any return statement? so that it will print

Yves Martin
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.
February 27, 2018

Question: have you mapped Behaviour to JIRA project or to Service Desk project (or both) ?

Vedant Kulkarni
Contributor
February 27, 2018

I have mapped it to only JIRA projects.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events