java play database_Play Framework连接到数据库

我一直在关注Play Framework的Typesafe在线培训(我是一个完整的网页设计初学者),一切正常,直到我们应该连接到数据库的部分 .

我遇到了一个问题,这是我尝试刷新浏览器时收到的错误消息:

Cannot connect to database [default]

In /Users/Arash/playconf/conf/application.conf at line 43.

40 db.default.driver=com.mysql.jdbc.Driver

41

# Here we add the database that we have created locally

43 db.default.url="jdbc:mysql://localhost:3306/playconf"

44

45 # We set this to root, we login as root with no password

46 db.default.user=root

这是我的终端中的错误消息(正在运行)

[错误] c.j.b.h.AbstractConnectionHook - 无法获得初始连接睡眠0ms并再次尝试 . 尝试离开:0 . 异常:null.Message:未知数据库'playconf'[错误]应用程序 - ! @ 6hmk31f56 - 内部服务器错误,用于(GET)[/] - > play.api.Configuration $$ anon $ 1:配置错误[无法连接到数据库[默认]] at play.api.Configuration $ .play $ api $ Configuration $$ configError(Configuration.scala:92)〜[play_2.10.jar:2.2.2] at play.api.Configuration.reportError(Configuration.scala:570)〜[play_2.10.jar:2.2.2] at at play.api.db.BoneCPPlugin $$ anonfun $ onStart $ 1.apply(DB.scala:252)〜[play-jdbc_2.10.jar:2.2.2] at play.api.db.BoneCPPlugin $$ anonfun $ onStart $ 1 .apply(DB.scala:243)〜[play-jdbc_2.10.jar:2.2.2]在scala.collection.TraversableLike $$ anonfun $ map $ 1.apply(TraversableLike.scala:244)〜[scala-library . jar:na] at scala.collection.TraversableLike $$ anonfun $ map $ 1.apply(TraversableLike.scala:244)〜[scala-library.jar:na]引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)〜[na:1.8.0] sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct)中的未知数据库'playconf' orAccessorImpl.java:62)〜[na:1.8.0] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)〜[na:1.8.0] at java.lang.reflect.Constructor.newInstance(Constructor . java:408)〜[na:1.8.0] at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)〜[mysql-connector-java-5.1.26.jar:na] at com.mysql . jdbc.Util.getInstance(Util.java:386)〜[mysql-connector-java-5.1.26.jar:na]

我尽可能精确地遵循了一切,但是我得到了这个错误,我整天都被困在这里 . 很沮丧......

然后我想,哦,也许我没有mysql?所以我用homebrew安装了mysql,并再次尝试,但得到了同样的错误 .

这是我的代码与数据库有关:

在配置文件中:

# We add our sql driver, which we have added in the build.sbt file

# db.default.driver=org.h2.Driver # This is the original, commented out originally

db.default.driver=com.mysql.jdbc.Driver

# Here we add the database that we have created locally

db.default.url="jdbc:mysql://localhost:3306/playconf"

# We set this to root, we login as root with no password

db.default.user=root

在构建文件中:

libraryDependencies ++= Seq(

javaEbean,

"mysql" % "mysql-connector-java" % "5.1.26",

"org.webjars" %% "webjars-play" % "2.2.0",

"org.webjars" % "bootstrap" % "2.3.1")

好吧,所以我似乎必须创建数据库,现在我已经这样做了,但我无法访问数据库 . 我得到ERROR 1044(42000):用户''@ localhost'访问被拒绝到数据库'playconf'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值