[英]How do I connect a android app to a mysql database 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;
}
}
我已经导入了jdbc库,并尝试使用DriverManager.registerDriver,但是它仍然崩溃了。出于明显的原因,我也更改了URL,用户名和密码。 请帮忙,谢谢!
通常,您不会像那样将mysql数据库暴露给Internet-您只是要求被黑客入侵。 通常,您将编写Web服务并将其公开。 然后,您的Android应用程序将调用Web服务以更新数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.