You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Play-2.6与Quill.io时加载数据源失败问题求助

Troubleshooting "Failed to Load Data Source" in Play/Scala (With Root No-Password DB)

Hey there! Since you and your team are new to Play and Scala, let's walk through the most likely causes for this error—no need to stress about the question being "too basic"—we've all been there!

First, let's start with the most common pitfalls:

1. Incomplete or Incorrect Database URL in application.conf

Play relies on the JDBC URL to locate your database, and even small typos can break things. Depending on which database you're using (PostgreSQL/MySQL), double-check your URL format:

  • PostgreSQL: Should look like jdbc:postgresql://localhost:5432/app-users (default port is 5432)
  • MySQL: Should look like jdbc:mysql://localhost:3306/app-users?useSSL=false&serverTimezone=UTC (default port is 3306; the extra params fix common 8.x connector issues)

Since your root user has no password, make sure you either:

  • Omit the password parameter entirely, or
  • Explicitly set it to an empty string in the URL or separate config line (some drivers require this to avoid confusion).

2. Missing Database Driver Dependency

Play doesn't include JDBC drivers out of the box—you need to add the correct one to your build.sbt file:

  • PostgreSQL:
    libraryDependencies += "org.postgresql" % "postgresql" % "42.6.0"
    
  • MySQL:
    libraryDependencies += "mysql" % "mysql-connector-java" % "8.0.33"
    

Make sure the driver version matches your database version (e.g., MySQL 8.x needs connector 8.x, not 5.x).

3. Incomplete Database Config in application.conf

Don't forget to define all required database settings! Here's a complete example for PostgreSQL (adjust driver for MySQL):

db.default.driver = org.postgresql.Driver
db.default.url = "jdbc:postgresql://localhost:5432/app-users"
db.default.user = root
db.default.password = ""  # Critical for no-password users—some drivers won't assume empty

The driver line is easy to overlook, but Play needs it to know which JDBC implementation to use.

4. User Connection Permissions (Even for Root!)

Just because you created the database as root doesn't mean root can connect via JDBC.

  • PostgreSQL: Check your pg_hba.conf file (usually in /var/lib/postgresql/<version>/main/ on Linux) to ensure there's a line allowing root from localhost with trust authentication (since no password):
    local   all             root                     trust
    host    all             root             127.0.0.1/32            trust
    
    After editing, restart PostgreSQL for changes to take effect.
  • MySQL: Verify root's host access with this query:
    SELECT user, host FROM mysql.user WHERE user='root';
    
    If root's host is localhost, you're good for local connections. If it's restricted to another host, update it with ALTER USER 'root'@'localhost' IDENTIFIED BY ''; (to ensure empty password is set correctly).

5. Database Service Isn't Running

Double-check that your database server is actually up and running!

  • Linux: Use systemctl status postgresql or systemctl status mysql
  • Windows: Check the Services list for PostgreSQL/MySQL and confirm it's started.

Quick Pre-Play Test

Before debugging Play further, try connecting to the database manually using the command line:

  • PostgreSQL: psql -U root app-users
  • MySQL: mysql -u root app-users
    If this fails, fix the database connection issue first—Play can't connect if even the command line can't!

内容的提问来源于stack exchange,提问作者jmkoni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:44:20