34
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DB接続設定 Spring-Boot application.properties

Last updated at Posted at 2019-08-04

はじめに

直近の仕事で、Spring-Bootでアプリ開発を続けています。
application.properties にDB接続設定を記述する必要がある度にGoogleで検索しています。
直ぐに記事が見つかるので、差支えはないのですが、割と頻繁に使うので、自分の記事にも残すことにしました。(悲しいかな、年のためか覚えても直ぐに忘れてしまうのです。年齢は関係ない?!)

# MYSQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/DB名
spring.datasource.username=ユーザー名
spring.datasource.password=パスワード
spring.jpa.database=MYSQL # JPAを使う場合は任意。なかったら自動判断
spring.jpa.hibernate.ddl-auto=update

# PostgreSQL
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/DB名
spring.datasource.username=ユーザー名
spring.datasource.password=パスワード

2019/12/08 追記

MyBatis で接続すると例外が発生。タイムゾーンの指定が必要。

### 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名?serverTimezone=JST

References

34
30
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
30

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?