Java 如何使用具有特殊字符的密码构造JDBCURL

Java 如何使用具有特殊字符的密码构造JDBCURL,java,jdbc,amazon-redshift,urlencode,Java,Jdbc,Amazon Redshift,Urlencode,无法使用jdbc连接url连接到红移 我的密码有特殊字符,例如:a(=b`git) 我的url是jdbc:redshift://localhost:5439/trsanalytics?user=user1&password=a%28%3Db%60git 我正在对密码进行编码并将其追加。仍然会出现以下错误 Amazon](500310)无效操作:用户密码身份验证失败 示例代码段 String encode_pwd = URLEncoder.encode(password,"UTF-8"); Str

无法使用jdbc连接url连接到红移

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

我的url是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)

一般的解决方案是不将用户名和密码作为参数包含在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)


conn一个通用的解决方案是在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)


conn首先尝试打印您的密码以测试是否正确。它是正确的,并且在我通过属性添加时有效。properties props=new properties();props.setProperty(“用户”,用户名);props.setProperty(“密码”,密码);executeQuery(DriverManager.getConnection(url,props));与encode_pwd.trim()一起工作finetry;如果可以使用属性,为什么不使用属性?在URL中提供密码是一个安全问题,因为可以使用
connection.getMetaData().getURL()检索URL
@Osmore为什么?首先尝试打印您的密码以测试是否正确。它是正确的,并且在我通过属性添加时有效。properties props=new properties();props.setProperty(“用户”,用户名);props.setProperty(“密码”,密码);executeQuery(DriverManager.getConnection(url,props));与encode_pwd.trim()配合使用;如果与属性配合使用,为什么不与属性配合使用?在URL中提供密码是一个安全问题,因为可以使用
connection.getMetaData().getURL()
@Osmore检索URL。为什么?