我正在尝试通过使用java Jacob library.来利用Windows搜索,但是在指定maxRecords选项以限制返回的行数方面遇到了麻烦。

我正在尝试通过使用以下行来做到这一点:

Dispatch.put(connection, "MaxRecords", new Variant(10));


建立连接后:

connection = new Dispatch("ADODB.Connection");
Dispatch.call(connection, "Open", "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");

//-------> error in the following line  <-------
Dispatch.put(connection, "MaxRecords", new Variant(10));

results = Dispatch.call(connection, "Execute",
        "SELECT System.ItemName, System.DateModified " +
        "FROM SystemIndex " +
        "WHERE Directory='file:C:/my/folder/path' AND Contains('a')").toDispatch();

while (!Dispatch.get(results, "EOF").getBoolean()) {
        Dispatch fields = Dispatch.get(results, "Fields").toDispatch();
        String filename = Dispatch.get(Dispatch.call(fields, "Item", new Integer(0)).toDispatch(), "Value").toString();
        String filedate = Dispatch.get(Dispatch.call(fields, "Item", new Integer(1)).toDispatch(), "Value").toString();
        list.put(filename, filedate);
        Dispatch.call(results, "MoveNext");
}


我究竟做错了什么?
编译没有错误,但是执行时得到以下消息:


  com.jacob.com.ComFailException:遇到COM异常:
  调用时:MaxRecords
  说明:80020007 /无命名参数。
  ...
  内部服务器错误(500)-服务器遇到意外情况,阻止其满足请求


当我通过URL访问我的restful时,这是一个:


  内部服务器错误
  
  服务器遇到意外情况,阻止其满足请求
  您可以获取技术详细信息here
  请继续访问我们的主页。


没有那条线,一切工作正常。

最佳答案

根据文档,Connection对象没有MaxRecords属性。我认为您想在RecordSet对象上设置MaxRecords。

编辑:

我没有尝试过这些,但是可以尝试以下方法:

connection = new Dispatch("ADODB.Connection");
Dispatch.call(connection, "Open", "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';");

String sql = "SELECT System.ItemName, System.DateModified " +
    "FROM SystemIndex " +
    "WHERE Directory='file:C:/my/folder/path' AND Contains('a')"

recordSet = new Dispatch("ADODB.Recordset");
Dispatch.put(recordSet, "MaxRecords", new Variant(10));

Dispatch.call(recordSet, "Open", sql, connection);

while (!Dispatch.get(recordSet, "EOF").getBoolean()) {
    ...
}

09-25 20:59