0

I wrote a jenkins pipeline with groovy that connects with the mysql database. But when it connects to mysql it shows"

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

". Is there is any way to resolve this error. If not how can I connect do mysql operations with jenkins pipeline. I wrote a below code to connect with mysql database.

def props = [user: '', password: '', allowMultiQueries: 'true'] as Properties
def url = 'jdbc:mysql://myserver:port/'
def driver = 'com.mysql.jdbc.Driver'
def sql = Sql.newInstance(url, props, driver)
echo 'Database connection sucess'

Thanks,

SAVe
  • 814
  • 6
  • 22
Prakash
  • 591
  • 3
  • 9
  • 28
  • 1
    Possible duplicate of [How to add a JDBC driver to a Jenkins pipeline?](https://stackoverflow.com/questions/40014632/how-to-add-a-jdbc-driver-to-a-jenkins-pipeline) – hakamairi May 22 '19 at 10:05
  • I am not clear with that answer can you please elaborate how to add jdbc driver in jenkins to avoid this exception "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" – Prakash May 22 '19 at 10:44
  • It is possible to use @Grab('mysql:mysql-connector-java:5.1.25') @GrabConfig(systemClassLoader = true) in groovy jenkins pipeline script. Jenkins shows "General error during conversion: No suitable ClassLoader found for grab" – Prakash May 22 '19 at 10:55
  • 1
    Did you install the plugin? – hakamairi May 22 '19 at 11:23
  • I installed two jenkins plugin "MySQL Database Plugin" and "MySQL Job Databases". I am using ubuntu operating system. what else I have to install? – Prakash May 22 '19 at 11:25

1 Answers1

0

The reason why you are getting that error is accuse MySQL JDBC connection jar is not accessible. Now possible reasons could be

sumit kumar
  • 150
  • 1
  • 2
  • 13
  • 1
    I am not clear with this answer can you please elaborate how to add jdbc driver in jenkins to avoid this exception "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" – Prakash May 22 '19 at 11:11