无法创建红移连接
Unable to create redshift connection
我正在尝试使用从 AWS redshift 集群控制台下载的 redshift jdbc 驱动程序创建 redshift 连接。低于异常
java.sql.SQLException: The connection attempt failed.
at com.amazon.redshift.util.RedshiftException.getSQLException(RedshiftException.java:48)
at com.amazon.redshift.Driver.connect(Driver.java:303)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at com.redshift.jdbc.test.ConnectionTest.main(ConnectionTest.java:27)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at com.amazon.redshift.core.RedshiftStream.<init>(RedshiftStream.java:86)
at com.amazon.redshift.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:101)
at com.amazon.redshift.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:214)
at com.amazon.redshift.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at com.amazon.redshift.jdbc.RedshiftConnectionImpl.<init>(RedshiftConnectionImpl.java:288)
at com.amazon.redshift.Driver.makeConnection(Driver.java:466)
at com.amazon.redshift.Driver.connect(Driver.java:279)
... 3 more
代码:
String jdbcURL = "jdbc:redshift://host:5439/database";
String user = "*****";
String password = "****";
String driver = "com.amazon.redshift.jdbc42.Driver";
Connection connection = null;
Statement statement = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(jdbcURL, user, password);
if (connection != null) {
System.out.println("Connection created!");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
谁能帮我解决为什么我无法建立连接?
我猜 Caused by: java.net.SocketTimeoutException: connect timed out
是一个关键,这里有几种可能性:
- 你的ip不在redshift安全组白名单
- 如果上面的代码正是您所用的 运行 那么
String jdbcURL = "jdbc:redshift://host:5439/database";
不包含正确的主机和数据库,它类似于
your-cluster-name.blahblahblah.eu-central-1.redshift.amazonaws.com:5439/your-database-name
你可以在 redshift console -> cluster general info 中找到这个作业 url
更新
查看你的安全组IP白名单
并添加您的 IP(如果此处不存在)
我正在尝试使用从 AWS redshift 集群控制台下载的 redshift jdbc 驱动程序创建 redshift 连接。低于异常
java.sql.SQLException: The connection attempt failed.
at com.amazon.redshift.util.RedshiftException.getSQLException(RedshiftException.java:48)
at com.amazon.redshift.Driver.connect(Driver.java:303)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at com.redshift.jdbc.test.ConnectionTest.main(ConnectionTest.java:27)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.base/java.net.PlainSocketImpl.waitForConnect(Native Method)
at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107)
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
at java.base/java.net.Socket.connect(Socket.java:591)
at com.amazon.redshift.core.RedshiftStream.<init>(RedshiftStream.java:86)
at com.amazon.redshift.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:101)
at com.amazon.redshift.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:214)
at com.amazon.redshift.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
at com.amazon.redshift.jdbc.RedshiftConnectionImpl.<init>(RedshiftConnectionImpl.java:288)
at com.amazon.redshift.Driver.makeConnection(Driver.java:466)
at com.amazon.redshift.Driver.connect(Driver.java:279)
... 3 more
代码:
String jdbcURL = "jdbc:redshift://host:5439/database";
String user = "*****";
String password = "****";
String driver = "com.amazon.redshift.jdbc42.Driver";
Connection connection = null;
Statement statement = null;
try {
Class.forName(driver);
connection = DriverManager.getConnection(jdbcURL, user, password);
if (connection != null) {
System.out.println("Connection created!");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (connection != null)
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
谁能帮我解决为什么我无法建立连接?
我猜 Caused by: java.net.SocketTimeoutException: connect timed out
是一个关键,这里有几种可能性:
- 你的ip不在redshift安全组白名单
- 如果上面的代码正是您所用的 运行 那么
String jdbcURL = "jdbc:redshift://host:5439/database";
不包含正确的主机和数据库,它类似于your-cluster-name.blahblahblah.eu-central-1.redshift.amazonaws.com:5439/your-database-name
你可以在 redshift console -> cluster general info 中找到这个作业 url
更新
查看你的安全组IP白名单
并添加您的 IP(如果此处不存在)