[JAVA] DB-Verbindungseinstellungen Spring-Boot application.properties

Einführung

In meinem letzten Job entwickle ich weiterhin Apps mit Spring-Boot. Jedes Mal, wenn ich DB-Verbindungseinstellungen in application.properties schreiben muss, suche ich bei Google. Ich kann den Artikel sofort finden, also ist es okay, aber ich benutze ihn ziemlich oft, also habe ich beschlossen, ihn in meinem Artikel zu belassen. (Leider, vielleicht wegen meines Alters, vergesse ich es sofort. Alter spielt keine Rolle ?!)

# MYSQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/DB-Name
spring.datasource.username=Nutzername
spring.datasource.password=Passwort
spring.jpa.database=MYSQL #Optional bei Verwendung von JPA. Automatische Beurteilung, wenn nicht
spring.jpa.hibernate.ddl-auto=update

# PostgreSQL
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/DB-Name
spring.datasource.username=Nutzername
spring.datasource.password=Passwort

Postskriptum 2019/12/08

Bei der Verbindung mit MyBatis tritt eine Ausnahme auf. Es ist notwendig, die Zeitzone anzugeben.

### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: The server time zone value '???? (?W????)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
spring.datasource.url=jdbc:mysql://localhost/DB-Name?serverTimezone=JST

References

Recommended Posts

DB-Verbindungseinstellungen Spring-Boot application.properties
db verbindungshinweise
[Java] Verbindung mit lokaler Datenbank (IntelliJ + SpringBoot)
DB-Verbindungsmethode-JDBC
JAVA DB-Verbindungsmethode
Versuchen Sie eine DB-Verbindung mit Java
Spring Boot-Anwendung, die DB-Verbindungseinstellungen mit Parametern angibt
Spring Boot DB-Verbindungspool
[PDO → DB-Verbindung mit Docker, PHP]