5
6

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.

Play Framework DBへの接続

Last updated at Posted at 2017-11-22

備忘録
#application.conf設定
conf/application.confに以下を追加

application.conf
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/playdb"
db.default.username=playdbuser
db.default.password="DBpassword"
ebean.default = ["models.*"]

または

application.conf
db {
 default.driver=com.mysql.jdbc.Driver
 default.url="jdbc:mysql://localhost:3306/dbname?characterEncoding=UTF8"
 default.username=username
 default.password=password
}
ebean.default = ["models.*"]

1行目は接続対象のRDBMSの設定を記述する。
上記はMySQLの設定

2行目はdb.default.url="jdbc:RDBMS名://ホスト/DB名?characterEncoding=UTF8"
な具合で?以後は文字コードの設定

3、4行目はユーザー名とパスワード
5行目は EbeanというPlay内蔵のO/Rマッパーの設定。使用するmodelクラスの設定をする。(通常はmodelsパッケージ内にmodelクラスをまとめるので上記でOK)

#build.sbt
以下の記述があるかを確認。

libraryDependencies += javaJdbc

デフォルトで以下のようになっているかも

build.sbt
libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs
)

上記の状態なら問題なし。

なければ追記しましょう。
それと下記を追記。
libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.8-dmr"

https://mvnrepository.com/
上記でサイトで検索してsbtのものをコピペでOK


ここまでで接続自体はOK!

5
6
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
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?