I am trying to connect to a redshift server and run some sql commands. Here is the code that I have written. 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)
But I am getting the following error.
我正在尝试连接到redshift服务器并运行一些sql命令。这是我写的代码。 Class.forName(“org.postgresql.Driver”)val url:String = s“jdbc:postgres:// $ {user}:$ {password} @ $ {host}:$ {port} / $ {database}” val连接: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: No suitable driver found for jdbc:postgres://user:password@host:port/database
java.sql.SQLException:没有为jdbc找到合适的驱动程序:postgres:// user:password @ host:port / database
But when I am using play framework's default database library with the same configuration, then I am able to connect to database successfully. Below is the configuration for the default 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"
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”
1 个解决方案
#1
0
The problem was with the url. The correct format for the url is "jdbc:postgresql://hostname:port/database".
问题出在网址上。 url的正确格式是“jdbc:postgresql:// hostname:port / database”。
#1
0
The problem was with the url. The correct format for the url is "jdbc:postgresql://hostname:port/database".
问题出在网址上。 url的正确格式是“jdbc:postgresql:// hostname:port / database”。