Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

658
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda