0

I'm trying to connect my android studio to my AWS rds with JDBC.

public void GetText(){
    TextView tx1 = findViewById(R.id.login_title);
    ConnectionURL = "jdbc:mysql://awsrds-endpoint:3306/supplychain?user=admin&password=admin123";

    try {
        System.out.println("Loading driver...");
        Class.forName("com.mysql.cj.jdbc.Driver");
        System.out.println("Driver loaded!");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Cannot find the driver in the classpath!", e);
    }

    Connection conn = null;
    Statement setupStatement = null;
    Statement readStatement = null;
    ResultSet resultSet = null;
    String results = "";
    int numresults = 0;
    String statement = null;

    try {
        System.out.println("Connecting ...");
        conn = DriverManager.getConnection(ConnectionURL);
        System.out.println("Connected");
        readStatement = conn.createStatement();
        resultSet = readStatement.executeQuery("SELECT S_ID FROM STAFF;");
        conn.close();

    } catch (SQLException ex) {
        System.out.println("SQLException: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }
}

and my error:

I/System.out: SQLException: Could not create connection to database server. SQLState: 08001 VendorError: 0

Gab
  • 1
  • Make sure that the security group of your RDS instance allow connections from outside world to port 3306. – Lejdi Prifti Nov 14 '21 at 16:28
  • Echoing one of the answers... [please reconsider your use of JDBC in an Android app](https://stackoverflow.com/questions/15853367/jdbc-vs-web-service-for-android). – CommonsWare Nov 14 '21 at 16:45

1 Answers1

2

The question here doesn't matter- do NOT connect to a db like this. In order to do this, you are putting your username and password in cleartext in your app. It is trivial to decompile the app and get it. This is unsafe. You should only ever access remote dbs via a webservice. That way your username and password do not need to leave your own devices.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127