In order to establish a MySQL connection I placed JDBC driver jar file to classpath:
/var/lib/jenkins/war/WEB-INF/lib/mysql-connector-j-8.4.0.jar
When I am running Groovy code in Jenkins I get the error No suitable driver found for jdbc:mysql://database/table
. If I restart Jenkins it will find the driver.
I believe the reason to that behavior is that I placed the driver into classpath after JVM started. So it has to be restarted in order to load the class.
Here is my code:
String url = "jdbc:mysql://host:port/db"
Properties info = new Properties()
info.setProperty("user", "${username}")
info.setProperty("password", "${password}")
info.setProperty("useSSL", "true")
info.setProperty("serverSslCert", "/path/to/cert")
Connection maildDbConnection = DriverManager.getConnection(url, info)
How can I load the class dynamically?