title: JDBC connecting to MySQL on Amazon ec2
body: <p>I'm a little new at that, but after starting my ec2 instance, and installing MySQL instance through RDS, I manage to connect to it through MySQL Workbench using ssh (.pem file).</p>
  
  <p>My problem is I can't seem to have it right, when I'm trying to connect with jdbc, how exactly the authentication suppose to be done?</p>
  
  <p>Here is my code, hope somebody can give me a hint on how to proceed:</p>
  
  <pre><code>public void create_table(){
      Connection c = null;
      Statement stmt = null;
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
          c = DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306/test","root", "password");
  
  //          c = DriverManager.getConnection ("jdbc:mysql://mydatabase.us-east-1.rds.amazonaws.com:3306/test","user="+"root"+"password=root", "");
  
  
  
  
  
        System.out.println("Opened database successfully");
  
        stmt = c.createStatement();
        String sql = "CREATE TABLE USERS " +
                     "(ID INT PRIMARY KEY   ," +
                     " DEVICE           TEXT    NOT NULL, " + 
                     " NAME            TEXT     NOT NULL)"; 
        stmt.executeUpdate(sql);
        stmt.close();
        c.close();
      } catch ( Exception e ) {
            System.err.println( e.getClass().getName() + ": " + e.getMessage() );
            System.exit(0);
      }
  </code></pre>
  
  <p><strong>EDIT</strong> </p>
  
  <p>I forgot few important details...</p>
  
  <ol>
  <li>I wrote my code in Java using Jersey and servelt.</li>
  <li>I Uploaded my WAR file to my ec2 instance.</li>
  </ol>
  
  <p>Now after both web-app and MySQL server are running on the same instance, <strong>I want to build the communication..</strong> </p>
  
  <p>Thank you!</p>