【发布时间】:2019-03-22 00:33:35
【问题描述】:
我正在使用 redshift jdbc 驱动程序连接到 redshift 集群,但连接在一段时间后断开。我将 tcpKeepAlive 设置为 1 分钟,但这也没有帮助。
这是我得到的例外:
java.sql.SQLException: [Amazon](500150) Error setting/closing
connection: Not Connected.
这是连接bean:
@Bean(name="redShiftConn")
public Connection connRedShift() {
Connection conn = null;
try{
Class.forName("com.amazon.redshift.jdbc42.Driver");
//Open a connection and define properties.
System.out.println("Connecting to database...");
Properties props = new Properties();
props.setProperty("user", user);
props.setProperty("password", password);
props.setProperty("tcpKeepAlive", "true");
props.setProperty("TCPKeepAliveMinutes", "1");
props.setProperty("ssl", "true");
props.setProperty("sslfactory",
"com.amazon.redshift.ssl.NonValidatingFactory");
conn =DriverManager.getConnection("jdbc:redshift://"+endpoint+":"+port+"/"+database, props);
return conn;
}catch(Exception e) {
System.out.println(e.toString());
}
return conn;
}
这里是maven依赖:
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42-no-awssdk</artifactId>
<version>1.2.10.1009</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.118</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-redshift</artifactId>
<version>1.11.118</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>1.11.118</version>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
【问题讨论】:
-
连接断开时会出现什么异常?
-
这是我得到的异常:java.sql.SQLException: [Amazon](500150) 设置/关闭连接时出错:未连接。
-
请将完整的异常堆栈跟踪添加到您的问题中
-
这就是我要回来的全部内容。
-
那是因为你用
System.out.println(e.toString()),改用e.printStackTrace()
标签: java spring-boot jdbc amazon-redshift aws-java-sdk