I am creating a new Spring Boot project (https://start.spring.io/), and I am not understanding the different dependencies provided for interfacing with relational databases.
The point of confusion is “JDBC API” and “PostgresSQL Driver”. My app needs to connect to a PostgreSQL database. So, which of the following are true?
-
JDBC API can be used to connect and operate with any relational (SQL) database (MySQL, PostgreSQL, etc.), and PostgresSQL Driver is not needed for JDBC API to work.
-
Both JDBC API and PostgresSQL Driver are needed for an application to connect to a PostgreSQL database.
-
The dependency PostgresSQL Driver includes JDBC API.
I have already googled about this, but there are only manuals of how to use them.
Answer
JDBC defines an API to connect and work with relational databases. The PostgreSQL driver is an implementation of this API for the PostgreSQL database.
You cannot use the JDBC API without an underlying driver to implement it. You could, however, use the driver directly, but drivers usually have very little guarantees about the stability of their APIs (other than what’s promised by JDBC, of course), so it would probably be a poor idea.