9

我试图在他们的 Yabe 教程中使用 Postgresql 和 Play 并得到这个错误:

无法连接到数据库,找不到驱动程序(org.postgresql.Driver)

这是我的连接字符串:

# If you need a full JDBC configuration use the following :
 db.url=jdbc:postgresql:yabe
 db.driver=org.postgresql.Driver  
 db.user=yabe
 db.pass=yabe
#
# Connections pool configuration :
 db.pool.timeout=1000
 db.pool.maxSize=30
 db.pool.minSize=1

在我的 lib 文件夹中,我有这个:postgresql-9.1-901.jdbc3.jar

我尝试将驱动程序名称更改为与 tha jar 相同的名称,但仍然出现相同的错误。有任何想法吗?

4

5 回答 5

40

如果您使用的是 Play 2.0,则其工作方式略有不同。网址实际上如下所示:

db.default.driver=org.postgresql.Driver
db.default.url="postgres://user:password@servername/dataBaseName"

但这也会出错,除非您在 build.scala 或 build.java 的依赖项部分添加以下行:

"postgresql" % "postgresql" % "9.1-901.jdbc4"
于 2012-05-28T15:12:11.287 回答
13

如果您需要 SSL 支持:

db=postgres://user:password@server.example.net:5432/dbname?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
于 2011-12-08T14:45:49.133 回答
10

Play 框架已经包含了 Postgres 的驱动程序。请执行下列操作:

  • 从您的 dependencies.yml 文件中删除对 postgreSQL 驱动程序的任何引用
  • 执行“播放 deps --sync”
  • 删除 lib/ 文件夹中与 postgreSQL 驱动程序相关的任何 jar
  • 将连接字符串更改为:

    db=postgres://user:pwd@localhost:5432/yabe

这应该可以解决您的冲突。

于 2011-10-13T11:05:48.967 回答
6

您不需要编辑完整的 JDBC 配置。我在本地使用 postgesql,我只是在 conf 文件夹的 application.conf 文件中添加这一行:

# To connect to a local PostgreSQL9 database, use:
db=postgres://userName:yourPassword@localhost:5432/nameOfYourDB

如果您在本地,除非您更改它,否则 userName 通常是 postgres。

于 2011-10-11T21:15:47.020 回答
3

您应该复制 PostgresSql 驱动程序版本“JDBC 4”[您拥有的是 JDBC 3]。从这里获取

或者,您可以- postgresql 9.1-901.jdbc4在依赖项中使用。但我认为 Maven 还没有这个最新版本。

于 2011-10-12T23:58:15.220 回答