无法连接到数据库 [db] MySql Play Frameworks 2.5.10
Cannot connect to database [db] MySql Play Frameworks 2.5.10
我正在使用 play framework 2.5.10。我正在尝试连接到数据库,但它显示 无法连接到数据库 [db]。我附上了我在 console, plugin.sbt 中遇到的错误。
build.sbt如下:
name := """zooengineer"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
application.config如下图:
## Database Connection Pool
# https://www.playframework.com/documentation/latest/SettingsJDBC
# ~~~~~
# Play doesn't require a JDBC database to run, but you can easily enable one.
#
# libraryDependencies += jdbc
#
play.db {
# The combination of these two settings results in "db.default" as the
# default JDBC pool:
config = "db"
default = "default"
# Play uses HikariCP as the default connection pool. You can override
# settings by changing the prototype:
prototype {
# Sets a fixed JDBC connection pool size of 50
#hikaricp.minimumIdle = 50
#hikaricp.maximumPoolSize = 50
}
}
## JDBC Datasource
# https://www.playframework.com/documentation/latest/JavaDatabase
# https://www.playframework.com/documentation/latest/ScalaDatabase
# ~~~~~
# Once JDBC datasource is set up, you can work with several different
# database options:
#
# Slick (Scala preferred option): https://www.playframework.com/documentation/latest/PlaySlick
# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA
# EBean: https://playframework.com/documentation/latest/JavaEbean
# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm
#
db {
# Default database configuration using MySQL database engine
# Connect to playdb as playdbuser
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
# Default database configuration using MySQL database engine
# Connect to playdb as playdbuser
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/zooengineer"
db.default.username=root
db.default.password="root123"
# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
#default.driver = org.h2.Driver
#default.url = "jdbc:h2:mem:play"
#default.username = sa
#default.password = ""
# You can turn on SQL logging for any datasource
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
#default.logSql=true
}
请帮忙连接数据库。
提前致谢。
编辑这一行:
db.default.url="jdbc:mysql://localhost/zooengineer"
至:
db.default.url="jdbc:mysql://localhost:3306/zooengineer"
Note:
Your JDBC URL format should be as follows:
jdbc:mysql://[host1][:port1][/[database]]
More help: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
在build.sbt
中添加下行
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
重新启动您的应用程序。
我正在使用 play framework 2.5.10。我正在尝试连接到数据库,但它显示 无法连接到数据库 [db]。我附上了我在 console, plugin.sbt 中遇到的错误。
build.sbt如下:
name := """zooengineer"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
application.config如下图:
## Database Connection Pool
# https://www.playframework.com/documentation/latest/SettingsJDBC
# ~~~~~
# Play doesn't require a JDBC database to run, but you can easily enable one.
#
# libraryDependencies += jdbc
#
play.db {
# The combination of these two settings results in "db.default" as the
# default JDBC pool:
config = "db"
default = "default"
# Play uses HikariCP as the default connection pool. You can override
# settings by changing the prototype:
prototype {
# Sets a fixed JDBC connection pool size of 50
#hikaricp.minimumIdle = 50
#hikaricp.maximumPoolSize = 50
}
}
## JDBC Datasource
# https://www.playframework.com/documentation/latest/JavaDatabase
# https://www.playframework.com/documentation/latest/ScalaDatabase
# ~~~~~
# Once JDBC datasource is set up, you can work with several different
# database options:
#
# Slick (Scala preferred option): https://www.playframework.com/documentation/latest/PlaySlick
# JPA (Java preferred option): https://playframework.com/documentation/latest/JavaJPA
# EBean: https://playframework.com/documentation/latest/JavaEbean
# Anorm: https://www.playframework.com/documentation/latest/ScalaAnorm
#
db {
# Default database configuration using MySQL database engine
# Connect to playdb as playdbuser
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
# Default database configuration using MySQL database engine
# Connect to playdb as playdbuser
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/zooengineer"
db.default.username=root
db.default.password="root123"
# https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
#default.driver = org.h2.Driver
#default.url = "jdbc:h2:mem:play"
#default.username = sa
#default.password = ""
# You can turn on SQL logging for any datasource
# https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
#default.logSql=true
}
请帮忙连接数据库。
提前致谢。
编辑这一行:
db.default.url="jdbc:mysql://localhost/zooengineer"
至:
db.default.url="jdbc:mysql://localhost:3306/zooengineer"
Note:
Your JDBC URL format should be as follows:
jdbc:mysql://[host1][:port1][/[database]]
More help: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html
在build.sbt
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
重新启动您的应用程序。