Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .doc_gen/metadata/s3-control_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ s3-control_CreateJob:
github: javav2/example_code/s3
sdkguide:
excerpts:
- description:
- description: Create an asynchronous S3 job.
snippet_tags:
- s3control.java2.create_job.async.main
- description: Create a compliance retention job.
snippet_tags:
- s3control.java2.create_job.compliance.main
- description: Create a legal hold off job.
snippet_tags:
- s3control.java2.create_job.compliance.main
services:
s3-control: {CreateJob}
s3-control_PutJobTagging:
Expand Down Expand Up @@ -108,10 +114,8 @@ s3-control_UpdateJobPriority:
services:
s3-control: {UpdateJobPriority}
s3-control_Basics:
title: Learn core operations for'&S3Control;' using an &AWS; SDK
title_abbrev: Learn core operations
synopsis: learn core operations for'&S3Control;'.
category: Scenarios
category: Basics
languages:
Java:
versions:
Expand Down
68 changes: 6 additions & 62 deletions java/example_code/redshift/ConnectToCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,17 @@

package connection;

import java.sql.*;
import java.util.Properties;

public class ConnectToCluster {
// Redshift driver:
// "jdbc:redshift://x.y.us-west-2.redshift.amazonaws.com:5439/dev";
static final String dbURL = "***jdbc cluster connection string ****";
static final String MasterUsername = "***master user name***";
static final String MasterUserPassword = "***master user password***";

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
// Dynamically load driver at runtime.
// Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver
// Redshift JDBC 4 driver: com.amazon.redshift.jdbc4.Driver
Class.forName("com.amazon.redshift.jdbc.Driver");

// Open a connection and define properties.
System.out.println("Connecting to database...");
Properties props = new Properties();

// Uncomment the following line if using a keystore.
// props.setProperty("ssl", "true");
props.setProperty("user", MasterUsername);
props.setProperty("password", MasterUserPassword);
conn = DriverManager.getConnection(dbURL, props);

// Try a simple query.
System.out.println("Listing system tables...");
stmt = conn.createStatement();
String sql;
sql = "select * from information_schema.tables;";
ResultSet rs = stmt.executeQuery(sql);
/*
The AWS SDK for Java v1 is on path to deprection. See:
https://aws.amazon.com/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/

// Get the data from the result set.
while (rs.next()) {
// Retrieve two columns.
String catalog = rs.getString("table_catalog");
String name = rs.getString("table_name");
See the V2 version of this code example here:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/javav2/example_code/redshift/src/main/java/com/example/redshift/ConnectToCluster.java
*/

// Display values.
System.out.print("Catalog: " + catalog);
System.out.println(", Name: " + name);
}
rs.close();
stmt.close();
conn.close();
} catch (Exception ex) {
// For convenience, handle all errors here.
ex.printStackTrace();
} finally {
// Finally block to close resources.
try {
if (stmt != null)
stmt.close();
} catch (Exception ex) {
} // nothing we can do
try {
if (conn != null)
conn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
System.out.println("Finished connectivity test.");
}
}
// snippet-end:[redshift.java.ConnectToCluster.complete]
2 changes: 1 addition & 1 deletion java/example_code/redshift/CreateAndDescribeSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class CreateAndDescribeSnapshot {
public static String clusterIdentifier = "***provide a cluster identifier***";
public static long sleepTime = 20;


public static void main(String[] args) throws IOException {

// Default client using the {@link
// com.amazonaws.auth.DefaultAWSCredentialsProviderChain}
client = AmazonRedshiftClientBuilder.defaultClient();

try {
// Unique snapshot identifier
String snapshotId = "my-snapshot-" + (new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss")).format(new Date());
Expand Down
114 changes: 114 additions & 0 deletions java/example_code/redshift/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Amazon Redshift code examples for the SDK for Java 1.x

## Overview

Shows how to use the AWS SDK for Java 1.x to work with Amazon Redshift.

<!--custom.overview.start-->
<!--custom.overview.end-->

_Amazon Redshift is a fast, fully managed, petabyte-scale data warehouse service that makes it simple and cost-effective to efficiently analyze all your data using your existing business intelligence tools._

## ⚠ Important

* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).

<!--custom.important.start-->
<!--custom.important.end-->

## Code examples

### Prerequisites

For prerequisites, see the [README](../../README.md#Prerequisites) in the `javav2` folder.


<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### Get started

- [Hello Amazon Redshift](src/main/java/com/example/redshift/HelloRedshift.java#L6) (`describeClusters`)


### Basics

Code examples that show you how to perform the essential operations within a service.

- [Learn the basics](src/main/java/com/example/scenario/RedshiftScenario.java)


### Single actions

Code excerpts that show you how to call individual service functions.

- [CreateCluster](src/main/java/com/example/scenario/RedshiftScenario.java#L498)
- [CreateTable](src/main/java/com/example/scenario/RedshiftScenario.java#L475)
- [DeleteCluster](src/main/java/com/example/scenario/RedshiftScenario.java#L247)
- [DescribeClusters](src/main/java/com/example/scenario/RedshiftScenario.java#L430)
- [DescribeStatement](src/main/java/com/example/scenario/RedshiftScenario.java#L324)
- [GetStatementResult](src/main/java/com/example/scenario/RedshiftScenario.java#L408)
- [Insert](src/main/java/com/example/scenario/RedshiftScenario.java#L265)
- [ModifyCluster](src/main/java/com/example/scenario/RedshiftScenario.java#L356)
- [Query](src/main/java/com/example/scenario/RedshiftScenario.java#L375)


<!--custom.examples.start-->
<!--custom.examples.end-->

## Run the examples

### Instructions


<!--custom.instructions.start-->
<!--custom.instructions.end-->

#### Hello Amazon Redshift

This example shows you how to get started using Amazon Redshift.


#### Learn the basics

This example shows you how to work with Amazon Redshift tables, items, and queries.


<!--custom.basic_prereqs.redshift_Scenario.start-->
<!--custom.basic_prereqs.redshift_Scenario.end-->


<!--custom.basics.redshift_Scenario.start-->
<!--custom.basics.redshift_Scenario.end-->


### Tests

⚠ Running tests might result in charges to your AWS account.


To find instructions for running these tests, see the [README](../../README.md#Tests)
in the `javav2` folder.



<!--custom.tests.start-->
<!--custom.tests.end-->

## Additional resources

- [Amazon Redshift Management Guide](https://docs.aws.amazon.com/redshift/latest/mgmt/welcome.html)
- [Amazon Redshift API Reference](https://docs.aws.amazon.com/redshift/latest/APIReference/Welcome.html)
- [SDK for Java 2.x Amazon Redshift reference](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/redshift/package-summary.html)

<!--custom.resources.start-->
<!--custom.resources.end-->

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
4 changes: 4 additions & 0 deletions javav2/example_code/s3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@
<groupId>software.amazon.awssdk</groupId>
<artifactId>iam-policy-builder</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>iam</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
Expand Down
Loading
Loading