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)
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
I already go through that problem but that doesn't solve it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
as shown in screenshot I imported the required package.
This is link from which I downloaded the mysql driver
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, the script is running on console with desired output but it's not running when I tried to run through behaviors
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Question: have you mapped Behaviour to JIRA project or to Service Desk project (or both) ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.