使用play-framework 2.5连接MySQL数据库

时间:2016-07-03 11:45:20

标签: java mysql scala intellij-idea playframework

尝试将MySQL数据库与Play-framework-Java连接 2.5.4

我收到错误

either dataSource or dataSourceClassName is required

这些是我在 App.conf 文件中使用的连接代码,

db {
  db.default.driver=com.mysql.jdbc.Driver
  db.default.url="jdbc:mysql://localhost:3306/playdb"
  db.default.user="root"
  db.default.password="9413678957"
}

但是在连接时它会给我以下错误:

caused by: java.lang.IllegalArgumentException: either dataSource or dataSourceClassName is required
    at com.zaxxer.hikari.HikariConfig.validate(HikariConfig.java:785)
    at play.api.db.HikariCPConfig.toHikariConfig(HikariCPModule.scala:141)
    at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:57)
    at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54)
    at scala.util.Try$.apply(Try.scala:192)
    at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54)
    at play.api.db.PooledDatabase.createDataSource(Databases.scala:199)
    at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:123)
    at play.api.db.DefaultDatabase.dataSource(Databases.scala:121)
    at play.api.db.DefaultDatabase.getConnection(Databases.scala:142)

当我连接到具有相同的mysql数据库时(与App.conf中相同)

  • url(jdbc:mysql:// localhost:3306 / playdb)
  • 用户名
  • 密码

使用 Intellij 工作正常

请告诉我我做错了什么来帮助我。

3 个答案:

答案 0 :(得分:6)

最后这对我有用: -

此错误导致我的时间过长。

这对我有用,

取消注释这些行。

    play.db {
             config = "db"
             default = "default" 
    } 

然后

    db {

  default.driver=com.mysql.jdbc.Driver
  default.url="jdbc:mysql://localhost:3306/playdb"
  default.username=root
  default.password="9403678957"
}

不需要db.default.*,因为您已经在数据库集范围内了。

非常感谢answer

答案 1 :(得分:0)

您不能在路径中指定db,您已经在config

的db部分中

所以:
分贝。 default.driver = com.mysql.jdbc.Driver
应该只是:
default.driver = com.mysql.jdbc.Driver Option Explicit Public Sub GetMinumum() Dim arr() arr = ThisWorkbook.Worksheets("Sheet3").Range("A1").CurrentRegion.Value Dim currColumn As Long Dim currMinimum As Double 'set starting value for comparison currMinimum = Application.WorksheetFunction.Min(Application.WorksheetFunction.Index(arr, 0, 1)) For currColumn = LBound(arr, 2) To UBound(arr, 2) If Application.WorksheetFunction.Min(Application.WorksheetFunction.Index(arr, 0, currColumn)) < currMinimum Then currMinimum = Application.WorksheetFunction.Min(Application.WorksheetFunction.Index(arr, 0, currColumn)) End If Next currColumn Debug.Print currMinimum End Sub

Option Explicit Public Sub GetMinumum() Dim arr() arr = ThisWorkbook.Worksheets("Sheet3").Range("A1").CurrentRegion.Value Dim currRow As Long Dim currMinimum As Double currMinimum = arr(1, 1) Dim outputValue As Variant outputValue = vbNullString For currRow = LBound(arr, 1) To UBound(arr, 1) If arr(currRow, 1) < currMinimum Then currMinimum = arr(currRow, 1) outputValue = arr(currRow, 2) End If Next currRow Debug.Print outputValue End Sub

答案 2 :(得分:-1)

查看此示例repo https://github.com/pedrorijo91/play-slick3-steps

您还可以看到我在http://pedrorijo.com/blog/play-slick/

所做的教程

虽然两者都打算玩2.4.x,但你应该能够理解你所犯的错误。不过,还有一个PR可以在https://github.com/pedrorijo91/play-slick3-steps/pull/2

升级到2.5.x