如何使用具有特殊字符的密码构造jdbc url

时间:2017-04-11 23:46:36

标签: java jdbc amazon-redshift urlencode

无法使用jdbc连接URL连接到redshift。

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

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

我正在编码密码并附加密码。我仍然收到以下错误

  

Amazon](500310)操作无效:用户

的密码验证失败

示例代码段

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

DriverManager.getConnection(url)

1 个答案:

答案 0 :(得分: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)