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

Redshift与Scala Play框架连接配置问题求助

Troubleshooting Redshift + Play + ScalikeJDBC Connection Issues

Hey there! Let's break down the issues in your current setup that are likely causing the connection failure—since you're new to this stack, it's easy to miss these small but critical details.

1. Wrong JDBC Driver Class

Your config uses org.redshift.Driver, but the official Redshift JDBC driver class is com.amazon.redshift.jdbc.Driver. This mismatch means Play can't find the correct driver to establish the connection.

2. Malformed JDBC URL

You have an extra trailing question mark in your URL: "jdbc:redshift://url:5439/myDb?". This invalidates the URL structure—remove the ? so it looks like:

db.default.url="jdbc:redshift://your-redshift-host:5439/myDb"

3. Redshift Dependency Glitch

In your build.sbt, the Redshift JDBC dependency has an extra space at the end of the version string: "1.2.10.1009 ". This tiny space will cause SBT to fail resolving the dependency. Also, for Scala 2.12 (which runs on Java 8+), it's better to use the redshift-jdbc42 artifact instead of jdbc4 for better compatibility.

4. Missing ScalikeJDBC-Play Integration

You added the core ScalikeJDBC dependency, but forgot the Play framework integration module (scalikejdbc-play). This module bridges ScalikeJDBC with Play's lifecycle and configuration, which is essential for the setup to work.


Corrected Configuration Files

application.conf

db.default.driver=com.amazon.redshift.jdbc.Driver
db.default.url="jdbc:redshift://your-redshift-url:5439/myDb"
db.default.username="your-username"
db.default.password="your-password"

play.modules.enabled += "scalikejdbc.PlayModule"
play.modules.disabled += "play.api.db.DBModule"

build.sbt

scalaVersion := "2.12.4"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test

libraryDependencies ++= Seq(
  "org.scalikejdbc" %% "scalikejdbc" % "3.2.1",
  "org.scalikejdbc" %% "scalikejdbc-play" % "2.6.0", // Match this to your Play version (e.g., 2.7.x for Play 2.7)
  "com.h2database" % "h2" % "1.4.196",
  "ch.qos.logback" % "logback-classic" % "1.2.3",
  "com.amazon.redshift" % "redshift-jdbc42" % "1.2.10.1009" // No trailing space, use jdbc42
)

resolvers += "redshift" at "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"

Additional Checks

  • Network Access: Make sure your application server's IP is allowed in your Redshift cluster's security group to access port 5439. This is a super common gotcha!
  • Version Matching: Double-check that the scalikejdbc-play version aligns with your Play framework version (e.g., if you're on Play 2.7, use 2.7.0 instead of 2.6.0).
  • Log Details: If you still run into issues, check your Play application logs for specific error messages (like "driver not found", "authentication failed", or "connection timeout")—these will point you directly to the root cause.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 03:48:15