【问题标题】:Java, count rows in azure database tableJava,计算天蓝色数据库表中的行数
【发布时间】:2016-04-17 02:36:42
【问题描述】:

我正在尝试计算 Azure 数据库表中的行数,并将该数字显示在我的 android 应用程序上。我在这里阅读了 Azure 关于从表中检索数据的文档:

https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-how-to-use-client-library/#querying

但它没有提到内置的 COUNT 函数。 Azure 库有 COUNT 函数吗?

【问题讨论】:

    标签: java android azure azure-sql-database


    【解决方案1】:

    正如@AlexChen-Wx所说,可以在Azure移动服务的JavaScript后端使用Object MobileServiceTableincludeTotalCount方法来统计记录数。

    如果你想直接依赖Android App,可以尝试使用Java类MobileServiceTableincludeInlineCount方法,源码请看https://github.com/Azure/azure-mobile-services/blob/master/sdk/android/src/sdk/src/main/java/com/microsoft/windowsazure/mobileservices/table/MobileServiceTable.java#L349

    【讨论】:

    • 使用这个?最终 MobileServiceList 结果 = mToDoTable.includeInlineCount().execute().get();
    • @Cian 是的,请尝试。
    • 它没有用,也没有:final MobileServiceList result = mToDoTable.where().includeInlineCount().execute().get();
    • @Cian 尝试编码int count = result.getTotalCount()
    【解决方案2】:

    是的,有一个名为includeTotalCount 的方法将返回所有记录的计数。详情请参考文章MobileServiceTable Object

    【讨论】:

      【解决方案3】:
       boolean loop = true;
       int totalrows = 0;
       int skipnumber = 0;
       int rows=0;
       while(loop) {
           int count = mToDoTable.select().skip(skipnumber).execute().get().size();
           skipnumber = skipnumber+50;
           rows = rows+count;
           if(rows<skipnumber){
                 loop=false;
                 totalrows = rows;
                 Log.i("count",String.valueOf(totalrows));
      
           }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-12
        相关资源
        最近更新 更多