通过sparql填充jtable导致格式字符串json

时间:2018-06-04 12:34:50

标签: java json sparql

我尝试用json数据填充jtable我试过像

这样的解决方案
String json = "
ObjectMapper mapper = new ObjectMapper();
 List<User> users = mapper.readValue(json,TypeFactory.defaultInstance().constructCollectionType(List.class, User.class));
UserTableModel model = new UserTableModel(users);
 tableSkill = new JTable(model);

但是eclipse给了我错误并要求我创建类User和User TableModel,所以我搜索了jar文件来导入它来解决这个问题,但是我没找到它。 任何人都可以帮助我,并告诉我我的错误在哪里

1 个答案:

答案 0 :(得分:0)

以下解决方案可避免您使用UserUser TableModel

public void runQuerytotable(Model model, String queryString, JTable table,int columns) {
    Query query = ARQFactory.get().createQuery(model, queryString);
    QueryExecution qexec = ARQFactory.get().createQueryExecution(query, model);
    ResultSet rs = qexec.execSelect();
    DefaultTableModel m = (DefaultTableModel) table.getModel();
    m.setColumnCount(columns); 
    String[] columnsName = {"URI","label"};
    m.setColumnIdentifiers(columnsName);
    while(rs.hasNext()) {   
        QuerySolution sol = rs.nextSolution();
        RDFNode URI = sol.get("s"); 
        RDFNode Label = sol.get("o"); 

        m.addRow(new Object[]{URI,Label});
    }
}