【发布时间】:2017-08-23 11:16:45
【问题描述】:
我遇到了与 Redshift 的 JDBC 连接问题,我无法完全解决。使用文档中给出的示例,当用户使用纯密码时,我可以轻松连接到 Redshift 集群,但是当用户的密码中包含 # 字符时,我会遇到身份验证失败。我可以使用两组凭据使用 SQL Workbench/J 连接到集群。当我使用以下时,没有连接问题。
DriverManager.setLoginTimeout(60);
Properties props = new Properties();
props.setProperty("user", "johndoe");
props.setProperty("password", "superSecret");
props.setProperty("tcpKeepAlive", "true");
Connection connection = DriverManager.getConnection("jdbc:redshift://xxxxxxx.us-east-1.redshift.amazonaws.com:5439/dev", props);
当我使用以下内容时,
DriverManager.setLoginTimeout(60);
Properties props = new Properties();
props.setProperty("user", "johndoehash");
props.setProperty("password", "superDouble#Secret");
props.setProperty("tcpKeepAlive", "true");
Connection connection = DriverManager.getConnection("jdbc:redshift://xxxxxxx.us-east-1.redshift.amazonaws.com:5439/dev", props);
我收到身份验证错误
java.sql.SQLException: [Amazon](500310) Invalid operation: password authentication failed for user "johndoehash";
at com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(ErrorResponse.java:1830)
at com.amazon.redshift.client.InboundDataHandler.read(InboundDataHandler.java:454)
at com.amazon.support.channels.AbstractSocketChannel.readCallback(Unknown Source)
at com.amazon.support.channels.PlainSocketChannel.read(Unknown Source)
Caused by: com.amazon.support.exceptions.ErrorException: [Amazon](500310) Invalid operation: password authentication failed for user "johndoehash";
我可以使用 SQL Workbench/J 使用两个帐户登录集群,但由于某种原因,我无法通过我的应用程序进行连接。关于我做错了什么有什么想法吗?
【问题讨论】:
-
您可以尝试将密码分配给一个变量,然后在 setproperty 中传递该密码。
-
是的,我已经这样做了并且得到了相同的结果。考虑到 # 可能会因为它在 http 中的使用而导致某种问题(??只是一个猜测)我试过 URLEncoder.encode(password, "UTF8") 效果没有区别。
-
对不起,我没有确切的解决方案,我不了解java,只是猜测,但有什么帮助,对吧?您是否尝试过使用 CHR(35)?
标签: java jdbc amazon-redshift