简体   繁体   中英

SQLException: Could not create connection to database server. SQLState: 08001

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM