【问题标题】:Attempt to have ResultSet from a CONSTRUCT query Exception尝试从 CONSTRUCT 查询异常中获取 ResultSet
【发布时间】:2011-08-04 11:04:11
【问题描述】:

我正在尝试使用以下查询:

QUERY="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
            " PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
                    "CONSTRUCT { \n" +
    "?cls ?cp ?co . \n" +
   " ?prop ?pp ?po . \n" +
"}" +
"WHERE { \n" +
    "?cls a rdfs:Class . \n" + 
    "?cls ?cp ?co .  \n" +
    "?prop a rdf:Property . \n" +
    "?prop ?pp ?po .  \n " + 
"}";

results = qe.execSelect();

查询在字符串变量 QUERY 中。
我正在使用耶拿 整个事情都在一个有 2 个按钮的界面中。 QUERY 在用户单击 button1 时进行选择查询,如果用户单击 button2,则进行上述查询

如果 QUERY 同时包含构造和选择,则会出现以下异常
线程“AWT-EventQueue-0”com.hp.hpl.jena.query.QueryExecException 中的异常:尝试从 CONSTRUCT 查询中获取 ResultSet 在 com.hp.hpl.jena.sparql.engine.QueryExecutionBase.execSelect(QueryExecutionBase.java:93)

【问题讨论】:

    标签: java semantics sparql jena


    【解决方案1】:

    CONSTRUCT 查询生成模型,而不是结果集。你需要使用:

    Model model = qe.execConstruct();
    

    您不能有一个“同时包含构造和选择”的查询。 (除非您的意思是包含子选择的构造?)

    您可能会发现以下内容很有用:

    Query q = QueryFactory.create(QUERY);
    
    if (q.isSelectType()) { ... execSelect, deal with results ... }
    else if (q.isConstructType()) { ... execConstruct, deal with result model ... }
    else { ... do you deal with DESCRIBE? ... }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      • 2018-12-10
      • 2013-03-25
      • 2012-05-30
      • 2021-09-13
      • 1970-01-01
      • 2016-10-14
      相关资源
      最近更新 更多