【问题标题】:how to construct jdbc url with password having special characters如何使用具有特殊字符的密码构造jdbc url
【发布时间】:2023-04-05 17:41:01
【问题描述】:

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

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

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

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

Amazon](500310) 无效操作:用户密码验证失败

示例代码sn-p

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

DriverManager.getConnection(url)

【问题讨论】:

  • 先试试打印你的密码来测试是否正确。
  • 这是正确的,当我通过属性添加时它可以工作。属性 props = new Properties(); props.setProperty("用户", 用户名); props.setProperty("密码", 密码); executeQuery(DriverManager.getConnection(url, props));工作正常
  • 尝试使用 encode_pwd.trim();
  • 如果它适用于属性,为什么不使用属性呢?在 URL 中提供密码是一个安全问题,因为可以使用 connection.getMetaData().getURL() 检索 URL。
  • @Osmore 试试为什么?

标签: java jdbc amazon-redshift urlencode


【解决方案1】:

对此的一般解决方案是不在 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)

【讨论】:

    猜你喜欢
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 2011-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    相关资源
    最近更新 更多