Home > Back-end >  How to let JdbcTemplate know suitable driver?
How to let JdbcTemplate know suitable driver?

Time:08-21

I have been having trouble with the following error.

SQLException: No suitable driver
Failed to get driver instance for jdbcUrl=jdbc:mysql:aurora://testing-customers:3306/customers

I am using gradle and groovy

It start happening when I updated spring version from 6 to 2.7. Meaning that, if i set the version back to 6, it works fine.

I have read other posts that talk about this issue. And I am sure that jdbc does not udnerstand what driver I want to use. So as others suggested, I have added the dirver property in the application.yaml

# application.yaml
cutomers:
  jdbc:
    driver: com.mysql.jdbc.Driver # I have also tried: org.mariadb.jdbc.Driver
    username: ~~~~
    password: ~~~~
    jdbcUrl: jdbc:mysql:aurora://testing-customers:3306/customers
@Configuration
public class Config {
  @ConfigurationProperties(prefix='customers.jdbc')
  public DataSource dataSource() {
    return DataSourceBuilder.create().build()
  }
}

However, the error does not go away. I am not sure why my jdbc having trouble finding the right driver.

This is the dependency

// build.gradle
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.30'

CodePudding user response:

  1. Firstly, check if the driver is available on the server and the server can establish a connection to the database

  2. Then, make sure you’re configuring your JDBC URL correctly.

Creating the JDBC URL : Base JDBC URL: jdbc:postgresql:///<DATABASE_NAME>

The JDBC URL is just like see below

jdbc:postgresql:///<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<POSTGRESQL_USER_NAME>&password=<POSTGRESQL_USER_PASSWORD>

Here are two possible resolutions to fix this issue:

Firstly, specify/add the class name for the driver in the JDBC Class Driver Name property on the Legacy Drivers tab for the stage. Secondly, configure Data Collector to automatically load specific drivers.

CodePudding user response:

mysql-connector version 5 requires

driver: com.mysql.jdbc.Driver

mysql-connector version 8 requires

driver: com.mysql.cj.jdbc.Driver
  • Related