import java.sql.*;
public class RedshiftExample {
public static void main(String[] args) {
String url = "jdbc:redshift://your-redshift-cluster-url:your-redshift-port/your-database";
String username = "your-username";
String password = "your-password";
try {
Class.forName("com.amazon.redshift.jdbc.Driver");
Connection connection = DriverManager.getConnection(url, username, password);
String query = "SELECT * FROM your-table";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);
while (resultSet.next()) {
String name = resultSet.getString("name");
int age = resultSet.getInt("age");
System.out.println("Name: " + name + ", Age: " + age);
}
resultSet.close();
statement.close();
connection.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}