我正在尝试连接到redshift服务器并运行一些sql命令。这是我写的代码:
Class.forName("org.postgresql.Driver")
val url: String = s"jdbc:postgres://${user}:${password}@${host}:${port}/${database}"
val connection: Connection = DriverManager.getConnection(url, user, password)
val statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
val setSearchPathQuery: String = s"set search_path to '${schema}';"
statement.execute(setSearchPathQuery)
但是我收到以下错误:
java.sql.SQLException:没有为jdbc找到合适的驱动程序:postgres:// user:password @ host:port / database
但是当我使用具有相同配置的play框架的默认数据库库时,我能够成功连接到数据库。以下是默认数据库的配置:
db.default.driver=org.postgresql.Driver
db.default.url="postgres://username:password@hostname:port/database"
db.default.host="hostname"
db.default.port="port"
db.default.dbname = "database"
db.default.user = "username"
db.default.password = "password"
答案 0 :(得分:0)
问题在于网址。网址的正确格式为:
jdbc:postgresql://hostname:port/database