0

我在测试漂亮的 SORM 库时遇到了问题。

当我尝试运行这样的代码时:

case class Coffee(name: String, supplier: Supplier, price: Double, sales: Int, total: Int)
case class Supplier(name: String, street: String, city: String, state: String, zip: String)

object Db extends Instance(
  entities = Set(Entity[Coffee](), Entity[Supplier]()),
  url = "jdbc:h2:mem:play",
  initMode = InitMode.Create
)

val supplier1 = Supplier("Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")
Db.save(supplier1)

我得到这样的例外:

Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106) ~[mchange-commons-java-0.2.3.jar:na]
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:641) ~[c3p0-0.9.2-pre5.jar:0.9.2-pre5]

我使用 Play 2.10,我的数据库配置如下所示:

 db.default.driver=org.h2.Driver
 db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""

我错过了什么吗?

提前致谢!

4

1 回答 1

0

这段代码运行得很好。问题一定出在您的设置中。例如,为了能够使用 H2 数据库,您需要将其包含在项目的依赖项中。

在我成功测试您的代码的 Maven 项目中,我具有以下依赖项:

<dependency>
  <groupId>com.h2database</groupId>
  <artifactId>h2</artifactId>
  <version>1.3.168</version>
</dependency>
于 2014-03-22T07:33:49.973 回答