If you use Java to develop and manage connections, you can use one of the following methods to connect to the RDS for MySQL test program:

  • Use Alibaba Cloud SDK to connect to the RDS for MySQL test program. To do so, you must install JDK1.7 or a later version and then use Apache Maven to install the Java SDK. You can click here to download the Alibaba Cloud SDK package.
  • Use MySQL Connector to connect to the RDS for MySQL test program. You can click here to download the required .jar package into the build path.
  • Use code to connect to the RDS for MySQL test program. An example of code is as follows:
        import java.sql.Connection;
        import java.sql.DriverManager;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.sql.Statement;
    
        public class mysqlconnection {
    
        public static void main(String[] args) {
    
        Connection conn = null;
               String sql;      
               String url = "jdbc:mysql://rdssoxxxxxxxxx.mysql.rds.aliyuncs.com:3306? zeroDateTimeBehavior=convertToNull&"
                       + "user=michael&password=password&useUnicode=true&characterEncoding=UTF8";
               try {
    
                   Class.forName("com.mysql.jdbc.Driver");            
                   conn = DriverManager.getConnection(url);
                   Statement stmt = conn.createStatement();
                  String  sqlusedb="use test_5";
    
                  int result1 = stmt.executeUpdate(sqlusedb);
    
                   sql = "create table teacher(NO char(20),name varchar(20),primary key(NO))";
                   int result = stmt.executeUpdate(sql);
                   if (result ! = -1) {
    
                       sql = "insert into teacher(NO,name) values('2016001','wangsan')";
                       result = stmt.executeUpdate(sql);
                       sql = "insert into teacher(NO,name) values('2016002','zhaosi')";
                       result = stmt.executeUpdate(sql);
                       sql = "select * from teacher";
                       ResultSet rs = stmt.executeQuery(sql);
                       System.out.println("Student ID\tName");
                       while (rs.next()) {
                           System.out
                                   .println(rs.getString(1) + "\t" + rs.getString(2));
                       }
                   }
               } catch (SQLException e) {
                   System.out.println("MySQL misoperation");
                   e.printStackTrace();
               } catch (Exception e) {
                   e.printStackTrace();
               } finally {
                   try {
        conn.close();
        } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
               }
    
        }
    
        }