3

I have some questions regarding the datasource in my application.properties

#Data Source properties
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/example
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

What exactly is the datasource.driver-class-name indicating?

James Westgate
  • 11,306
  • 8
  • 61
  • 68
Ethan Wan
  • 33
  • 1
  • 5
  • You often won’t need to specify the `driver-class-name` since Spring Boot can deduce it for most databases from the `url`. See [Spring Boot 3.0.2 Data docs](https://docs.spring.io/spring-boot/docs/3.0.2/reference/html/data.html#data). – Marco Lackovic Feb 08 '23 at 17:13
  • Becareful using 'com.mysql.jdbc.Driver' since it has been deprecated. use `com.mysql.cj.jdbc.Driver` instead. Reference: https://stackoverflow.com/a/53829100/13903942 – Federico Baù Jun 03 '23 at 11:38

2 Answers2

2

This name refer to the classname of the JDBC driver for communicating with your database. This class will be loaded at launch time (it must be available in the classpath).

Mickaël B.
  • 325
  • 4
  • 14
1

The url is the location of your database. Here you are saying my database is located at http://localhost:3306/example where example is the database name.

The DriverClassName is the name of the JDBC driver that you use to talk to your database. in case one of the Spring data libraries like JDBC or JPA is used you can omit that property.

Daniel Jacob
  • 1,455
  • 9
  • 17