简体   繁体   中英

How do I connect a android app to a mysql database that is not local?

Hey I have found plenty of tutorials for people who are making the databases on their own computer but I am trying to connect to one that is not local

private class SignUpA extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        String url = "jbdc:mysql://mywbdb.cjymdxzuzy46.us-east-1.rds.amazonaws.com:3306/mysql";
        String dbName = "profiles";
        String driver = "com.mysql.jdbc.Driver";
        Properties userInfo = new Properties();
        userInfo.put("user", "user");
        userInfo.put("password", "pass");

        try {

            Class.forName(driver);

            Connection conn = DriverManager.getConnection(url + dbName,
                    userInfo);
            CharSequence text = "Hello toast!";
            Toast tost = Toast.makeText(getApplicationContext(), text,
                    Toast.LENGTH_LONG);
            tost.show();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

I have imported the jdbc library and have tried using the DriverManager.registerDriver also but it still crashed.Also I changed the url and the username and password for obvious reasons. Please help, Thanks!

You wouldn't normally expose a mysql database to the Internet like that - your just asking to be hacked. Typically you would write a Web Service and expose that instead. Then your Android app would make calls to the Web Service to update the database.

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