I am trying to use newInstance method from groovy.sql.Sql
library to connect to mysql.
Based on my research and reading a lot of stackoverflow questions here is a summary of what needs to be done:
import groovy.sql.Sql
def url = 'jdbc:mysql://<host>:<port>/<database>'
def user = 'user'
def password = 'pasword'
def driver = 'com.mysql.jdbc.Driver'
def sql = Sql.newInstance(url, user, password, driver)
// use 'sql' instance ...
sql.close()
For this to work I need to do the following:
- Download mysql jdbc driver from here
- Add it to Jenkins classpath
However, I do not want to download extra jar files to my app.
As an alternative solution, I found the database-mysql Jenkins plugin. If I understand correctly, the plugin is executing the 2 steps I listed above (download mysql jdbc driver and add it to Jenkins classpath).
However, I am not sure if that is correct. I am very confused on how to use it.
Once I add the plugin, how do I use it to make my code above work?