如何从Azure的数据库表的数据到一个Android应用程序? [英] How to Get data from Azure DB Table to an Android app?

查看:461
本文介绍了如何从Azure的数据库表的数据到一个Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的蔚蓝,我不知道如何连接到一个表我在一个Azure数据库创建。我想要得到的表数据(SELECT *),并对其进行填充在GridView的机器人。我知道了填充的一部分使用的适配器,所有我想知道的是如何连接并从表接收数据:)

I'm new to azure, I don't know how to connect to a Table I created on an Azure Database. I want to get the table data (SELECT *) and populate them in a GridView in android. I know the 'populating' part using an adapter, all I want to know is how to connect and receive the data from the Table :)

我试过<一href="http://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-get-started-data/?rnd=1"相对=nofollow>此内容教程由微软但是,我申请相同的教程,我的方案时面临一些困难。

I've tried THIS tutorial by Microsoft however, I'm facing some difficulties when applying the same tutorial to my scenario.

下面是我的尝试:

@Override

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);



setContentView(R.layout.activity_home_screen);

    try {
        mClient = new MobileServiceClient(
                "LINK",
                "KEY",
                this);

} catch (MalformedURLException e) {

}

    refreshItemsFromTable();
 }



private void refreshItemsFromTable()
{
          //ActivityData is my Entity class 

        new AsyncTask<Void, Void, Void>() {
            //
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    //This is the problematic area. My actual table's name is "Activity" on the Azure SQL
                    final MobileServiceList<ActivityData> result = mToDoTable.eq(false).execute().get();
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            mAdapter.clear();

                            for (ActivityData item : result) {
                                mAdapter.add(item);
                            }
                        }
                    });
                } catch (Exception exception) {
                    Toast.makeText(HomeScreen.this, exception.toString(),Toast.LENGTH_LONG);
                }
                return null;
            }
        }.execute();
    }

如何指定在这种情况下的SQL SELECT查询?看起来这code不是要做到这一点?我想填充GridView控件与表中的数据:)

How do I specify the SQL SELECT query in this scenario? Looks like this code isn't the way to do it? I would like to populate a GridView with the table data :)

推荐答案

最有把握的方式,你会得到数据的Azure表存储到你的Andr​​oid是通过REST API。这是比较简单的,你有完全的控制。

Most sure way that you will get data from Azure Table Storage to your android is via REST API. It is relatively straight forward and you have full control.

例如,获取(查询)的数据,你可以检查以下示例请求:

For example, to fetch (query) data you can check the following sample request:

Request Syntax:
GET /myaccount/Customers()?$filter=(Rating%20ge%203)%20and%20(Rating%20le%206)&$select=PartitionKey,RowKey,Address,CustomerSince  HTTP/1.1

Request Headers:
x-ms-version: 2013-08-15
x-ms-date: Mon, 25 Nov 2013 15:25:14 GMT
Authorization: SharedKeyLite myaccount:<some key>
Accept: application/atom+xml,application/xml
Accept-Charset: UTF-8
DataServiceVersion: 2.0;NetFx
MaxDataServiceVersion: 2.0;NetFx

更多关于是:

More on that:

  • https://msdn.microsoft.com/en-us/library/azure/dd179421.aspx
  • https://msdn.microsoft.com/en-us/library/azure/dd179423.aspx

请注意,Azure的表不支持SQL语言。 Azure的表是完全不同类型的存储(所谓的无-SQL)。

Please note that Azure tables does not support SQL language. Azure Tables are totally different type of storage (so called no-sql).

这篇关于如何从Azure的数据库表的数据到一个Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆