2011-04-13 49 views
1

我試圖使用以下查詢:嘗試有結果集從構造查詢異常

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。
我正在使用jena 整個事情是在有2個按鈕的界面。 查詢需要選擇查詢,當用戶單擊button和上述查詢,如果用戶點擊BUTTON2

得到以下異常,如果查詢包含構建和選擇在線程
異常「AWT-EventQueue的-0」 com.hp .hpl.jena.query.QueryExecException:嘗試在com.hp.hpl.jena.sparql.engine.QueryExecutionBase.execSelect(QueryExecutionBase.java:93)具有結果集從一個構造查詢

回答

4

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? ... }