如何用有特殊字符的密码来构建jdbc的url

问题描述 投票:1回答:1

无法使用jdbc连接网址连接到redshift。

我的密码有特殊字符,例如:a(=b`git。

我的url是jdbc:redshift:/localhost:5439trsanalytics?user=user1&password=a%28%3Db%60git。

我正在对密码进行编码并追加密码。但我还是得到以下错误信息

亚马逊](500310)无效操作:用户密码认证失败。

示例代码片段

String encode_pwd = URLEncoder.encode(password,"UTF-8");
String fullUrl = url + "?user=" + username + "&password=" + encode_pwd;

DriverManager.getConnection(url)
java jdbc amazon-redshift urlencode
1个回答
0
投票

一般的解决方案是在URL字符串中不包含用户名和密码作为参数,而是在getConnection调用中作为附加参数传递。

在Java中,可以这样做。

// Don't URL encode the password
//String encode_pwd = URLEncoder.encode(password,"UTF-8");
// Don't include the user and password parameters in the url string
//String fullUrl = url + "?user=" + username + "&password=" + encode_pwd;

// Pass the parameters to the getConnection string
DriverManager.getConnection(url, user=username, password=password)

在R中,使用RJDBC,这样做:


conn <- dbConnect(
  driver,
  url,
  user=username,
  password=password)
© www.soinside.com 2019 - 2024. All rights reserved.