嘿,我已经为那些在自己的计算机上创建数据库的人找到了很多教程,但我正在尝试连接到一个非本地的数据库
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;
}
}
我已经导入了 jdbc 库并尝试使用 DriverManager.registerDriver 但它仍然崩溃了。我还更改了 url 以及用户名和密码,原因很明显。请帮忙,谢谢!
最佳答案
您通常不会像那样将 mysql 数据库公开到 Internet - 您只是要求被黑客入侵。通常,您会编写一个 Web 服务并将其公开。然后您的 Android 应用程序将调用 Web 服务来更新数据库。
关于java - 如何将 android 应用程序连接到非本地的 mysql 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22624971/