Add mysql driver to API REST Extension

1
0
-1

Hello everybody,

I trying to develop an API REST EXtension that connects to an Mysql database. I loaded all the dependencies (mysql driver included) in the rest extension pom.xml and build/deploy the package. But, when i tried to call the rest method i developed from chrome, i receive the following error in the log:

No suitable driver found for jdbc:mysql://localhost:3306/baseexample

clearly, the mysql driver was not loaded, but i cannot find a way to load the driver from the source. This is my connection method:

`package com.conexion

import java.sql.Connection
import java.sql.DriverManager
import java.sql.SQLException

import org.slf4j.Logger
import org.slf4j.LoggerFactory

class Conexion {
    private static final Logger LOGGER = LoggerFactory.getLogger(Conexion.class);
    private Connection con;

    public Connection getCon() {
        return con;
    }

    public void conectar(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/baseexample","root", "");
            if(con!=null) {
                LOGGER.info("######################### Conexion satisfactoria ############################");
            }
        } 
        catch (SQLException e) {
            LOGGER.info("######################### Error en la conexion: "+e.getMessage()+" #########################");
        }
    }
}`
1 answer

1
0
-1

Hi escalantereniery,

It would seem as though the application server were not finding the driver (the actual .jar file, that is). Could you check that the mysql driver is present in your application server's CLASSPATH all right?

For example, if you are running a Tomcat bundle, could you try putting it under {TOMCAT_HOME}/server/lib/bonita/? (This is for example the same case that was raised in [this article). I hope this helps.

Regards, Unai

Notifications