gpt4 book ai didi

android - android 在线访问mysql数据库

转载 作者:行者123 更新时间:2023-11-29 13:40:52 24 4
gpt4 key购买 nike

我们正在构建一个网络应用程序和一个移动应用程序,我们正在使用 mysql 数据库构建网络应用程序。我不想为移动应用程序使用单独的 sqlite 数据库,我想使用相同的 mysql 数据库。任何人都可以提供有关此可行性的见解和示例 fragment (如果有)如何在线连接到 mysql 数据库并提取数据

最佳答案

您需要通过具有适当安全性的服务层公开您的数据库。假设您的网络应用程序是 example.com 并且您需要使用登录。因此,您需要一个验证登录的服务,该服务将接受 POST 数据中的用户名和密码。

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.example.com/validateuser");
// Add your data
List < NameValuePair > nameValuePairs = new ArrayList < NameValuePair > (2);
nameValuePairs.add(new BasicNameValuePair("user", "foo"));
nameValuePairs.add(new BasicNameValuePair("pass", "md5_string_of_input"));

try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
try {
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());

} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

类似于发布内容并从您的网络应用程序获取响应。请注意,这不是完整的答案,您所要求的内容无法在这里得到解答

关于android - android 在线访问mysql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18095688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com