Skip to content

Commit 4cb6531

Browse files
committed
updated RS V1 code example to point to V2
1 parent 2b76a5e commit 4cb6531

File tree

1 file changed

+6
-62
lines changed

1 file changed

+6
-62
lines changed

java/example_code/redshift/ConnectToCluster.java

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,17 @@
55

66
package connection;
77

8-
import java.sql.*;
9-
import java.util.Properties;
10-
118
public class ConnectToCluster {
129
// Redshift driver:
1310
// "jdbc:redshift://x.y.us-west-2.redshift.amazonaws.com:5439/dev";
14-
static final String dbURL = "***jdbc cluster connection string ****";
15-
static final String MasterUsername = "***master user name***";
16-
static final String MasterUserPassword = "***master user password***";
17-
18-
public static void main(String[] args) {
19-
Connection conn = null;
20-
Statement stmt = null;
21-
try {
22-
// Dynamically load driver at runtime.
23-
// Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver
24-
// Redshift JDBC 4 driver: com.amazon.redshift.jdbc4.Driver
25-
Class.forName("com.amazon.redshift.jdbc.Driver");
26-
27-
// Open a connection and define properties.
28-
System.out.println("Connecting to database...");
29-
Properties props = new Properties();
30-
31-
// Uncomment the following line if using a keystore.
32-
// props.setProperty("ssl", "true");
33-
props.setProperty("user", MasterUsername);
34-
props.setProperty("password", MasterUserPassword);
35-
conn = DriverManager.getConnection(dbURL, props);
3611

37-
// Try a simple query.
38-
System.out.println("Listing system tables...");
39-
stmt = conn.createStatement();
40-
String sql;
41-
sql = "select * from information_schema.tables;";
42-
ResultSet rs = stmt.executeQuery(sql);
12+
/*
13+
The AWS SDK for Java v1 is on path to deprection. See:
14+
https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/
4315
44-
// Get the data from the result set.
45-
while (rs.next()) {
46-
// Retrieve two columns.
47-
String catalog = rs.getString("table_catalog");
48-
String name = rs.getString("table_name");
16+
See the V2 version of this code example here:
17+
https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift/src/main/java/com/example/redshift/ConnectToCluster.java
18+
*/
4919

50-
// Display values.
51-
System.out.print("Catalog: " + catalog);
52-
System.out.println(", Name: " + name);
53-
}
54-
rs.close();
55-
stmt.close();
56-
conn.close();
57-
} catch (Exception ex) {
58-
// For convenience, handle all errors here.
59-
ex.printStackTrace();
60-
} finally {
61-
// Finally block to close resources.
62-
try {
63-
if (stmt != null)
64-
stmt.close();
65-
} catch (Exception ex) {
66-
} // nothing we can do
67-
try {
68-
if (conn != null)
69-
conn.close();
70-
} catch (Exception ex) {
71-
ex.printStackTrace();
72-
}
73-
}
74-
System.out.println("Finished connectivity test.");
75-
}
7620
}
7721
// snippet-end:[redshift.java.ConnectToCluster.complete]

0 commit comments

Comments
 (0)