title: Using JDBC to connect with AWS Redshift
body: <p>I wanted to connect and insert data into my Amazon Redshift table using JDBC. I wrote the following code but keep getting an error at line Class.forName</p>
  
  <pre><code>import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.Properties;
  
  public class RedShiftDataEmitter {
      static final String redshiftUrl = "jdbc:redshift://xxxxxxxxx:5439/xxxxxx";
      static final String masterUsername = "xxxxxxx";
      static final String password = "xxxxxxx";
  
      public static void main(String[] args) {
          Connection connection = null;
          Statement statement = null;
  
          try {
              Class.forName("com.amazon.redshift.jdbc41.Driver");
              Properties properties = new Properties();
              properties.setProperty("user", masterUsername);
              properties.setProperty("password", password);
              connection = DriverManager.getConnection(redshiftUrl, properties);
              // Further code to follow
          } catch(ClassNotFoundException cnfe) {
              cnfe.printStackTrace();
          } catch (SQLException sqle) {
              sqle.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Just a heads-up, I can connect to the same cluster using SQL Workbench. My pom.xml is as below</p>
  
  <pre><code>&lt;!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-redshift --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.amazon.redshift&lt;/groupId&gt;
        &lt;artifactId&gt;redshift-jdbc41&lt;/artifactId&gt;
        &lt;version&gt;1.2.1.1001&lt;/version&gt;
    &lt;/dependency&gt;
  </code></pre>