0

我们正在构建一个网络应用程序和一个移动应用程序,我们正在使用 mysql 数据库构建网络应用程序。我不想为移动应用程序使用单独的 sqlite 数据库,我想使用相同的 mysql 数据库。谁能提供有关如何在线连接到 mysql 数据库和提取数据的可行性和示例片段的见解

4

1 回答 1

1

您需要通过具有适当安全性的服务层公开您的数据库。假设您的网络应用程序是 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();
 } 

喜欢发布并从您的网络应用程序中获得响应的东西。请注意,这不是一个完整的答案,您所要求的不能在这里回答

于 2013-08-07T06:07:33.947 回答