Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

659
Views
Why Jenkins pipeline throwing java.lang.ClassNotFoundException: com.mysql.jdbc.Driver?

The exception thrown by Jenkins pipeline.

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

I've already installed Database Plugin and MySQL Database Plugin.

But still I'm getting this exception.

The pipeline code :

import groovy.sql.Sql

node('master'){
    Class.forName("com.mysql.jdbc.Driver")
    def sql = Sql.newInstance("jdbc:mysql://10.10.115.38:3306/test", "root","123456", "com.mysql.jdbc.Driver")
    def rows = sql.execute "select count(*) from test;"
    echo rows.dump()
}

Exception message:

 Running on Jenkins in /var/jenkins_home/workspace/test-jdbc
 [Pipeline] {
 [Pipeline] }
 [Pipeline] // node
 [Pipeline] End of Pipeline
 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:352)

I'm using Jenkins version 2.222.1

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The reason for this java.lang.ClassNotFoundException: com.mysql.jdbc.Driver is that the MySQL Connector/J jar is missing.

Note: If you are using higher version of MySQL Connector/J, then it is recommended to use com.mysql.cj.jdbc.Driver instead of com.mysql.jdbc.Driver

I updated your script.

import groovy.sql.Sql

node('master'){
    Class.forName("com.mysql.cj.jdbc.Driver")
    def sql = Sql.newInstance("jdbc:mysql://10.10.115.38:3306/test", "root","123456", "com.mysql.cj.jdbc.Driver")
    def rows = sql.execute "select count(*) from test;"
    echo rows.dump()
}

Download the jar from here : https://mvnrepository.com/artifact/mysql/mysql-connector-java

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!