0

有我的配置:

 db.default.driver=com.mysql.jdbc.Driver
 db.default.url="jdbc:mysql:root:play2test" //Cannot connect to database [default] -> play mark this line
 db.default.user=root
 db.default.pass=123456

我已经使用 MySql-workbench 创建了 play2test.mwb,我尝试了其他方式,例如:

 db.default.driver="com.mysql.jdbc.Driver"
 db.default.url="jdbc:mysql:root:play2test" 
 db.default.user="root"
 db.default.pass="123456"

但总是会出现此错误:db 的类型为 STRING 而不是 OBJECT

在终端:

[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial connection Sleeping for 0ms and trying again. Attempts left: 0. Exception: null
[error] application - 

! @6epj0nb4d - Internal server error, for request [GET /] ->

play.api.Configuration$$anon$1: Configuration error [Cannot connect to database [default]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:71) ~[play_2.9.1.jar:2.0.4]
    at play.api.Configuration.reportError(Configuration.scala:258) ~[play_2.9.1.jar:2.0.4]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:249) ~[play_2.9.1.jar:2.0.4]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:240) ~[play_2.9.1.jar:2.0.4]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194) ~[scala-library.jar:0.11.3]
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194) ~[scala-library.jar:0.11.3]
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql:root:play2test
    at java.sql.DriverManager.getConnection(DriverManager.java:640) ~[na:1.6.0_27]
    at java.sql.DriverManager.getConnection(DriverManager.java:200) ~[na:1.6.0_27]
    at com.jolbox.bonecp.BoneCP.obtainRawInternalConnection(BoneCP.java:256) ~[bonecp.jar:0.7.1.RELEASE]
    at com.jolbox.bonecp.BoneCP.<init>(BoneCP.java:305) ~[bonecp.jar:0.7.1.RELEASE]
    at com.jolbox.bonecp.BoneCPDataSource.maybeInit(BoneCPDataSource.java:150) ~[bonecp.jar:0.7.1.RELEASE]
    at com.jolbox.bonecp.BoneCPDataSource.getConnection(BoneCPDataSource.java:112) ~[bonecp.jar:0.7.1.RELEASE]

我试图取消评论

ebean.default="models.*"

并添加了 sbt 依赖项:

 "mysql" % "mysql-connector-java" % "5.1.21"

但它没有工作:((((那么我怎么能解决它:(。

对不起,如果我的英语不好

4

3 回答 3

5

尝试以下方式:

   db.default.url="jdbc:mysql://your_server_address:3306/play2test" 
   db.default.driver="com.mysql.jdbc.Driver"
   db.default.user=root
   db.default.pass="123456"
   db.default.host=your_server_address
于 2013-07-09T11:23:54.133 回答
2

您的连接网址格式错误。尝试使用:

db.default.url="jdbc:mysql://localhost/play2test"

并确保在 /project/Build.scala 中设置产品依赖项,将 5.1.25 更改为 mysql 连接器的任何版本

val appDependencies = Seq(

"mysql" % "mysql-connector-java" % "5.1.25"

)

并且在同一个文件中,确保该行没有被注释

ebean.default="models.*"
于 2013-07-09T08:11:26.487 回答
0

网址应该类似于:

db.default.url="jdbc:mysql://your_server_address/play2test"
于 2013-07-09T08:10:07.567 回答