import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class RedshiftExample {
public static void main(String[] args) {
// Database connection parameters
String redshiftUrl = "jdbc:redshift://redshift-cluster-endpoint:5439/database";
String username = "your-username";
String password = "your-password";
// Connection object
Connection conn = null;
try {
// Create a connection to Redshift
conn = DriverManager.getConnection(redshiftUrl, username, password);
// Perform database operations
} catch (SQLException e) {
e.printStackTrace();
} finally {
// Close the connection
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class RedshiftQueryExample {
public static void main(String[] args) {
// Database connection parameters
String redshiftUrl = "jdbc:redshift://redshift-cluster-endpoint:5439/database";
String username = "your-username";
String password = "your-password";
// Connection object
Connection conn = null;
try {
// Create a connection to Redshift
conn = DriverManager.getConnection(redshiftUrl, username, password);
// Create a statement
Statement stmt = conn.createStatement();
// Execute a SELECT query
ResultSet rs = stmt.executeQuery("SELECT * FROM table_name;");
// Process the result set
while (rs.next()) {
// Retrieve data from each row
String column1 = rs.getString("column1");
int column2 = rs.getInt("column2");
// Do something with the data
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
// Close the connection
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}