如何从java中的数组中获取不同的查询

时间:2015-05-27 14:22:14

标签: java mysql

我有一个包含多个重复查询的数据库。我可以从数据库中提取唯一的查询,但是当我尝试获取该查询的不同字形时,我会得到所有重复的查询。我如何消除重复的查询。

ArrayList < String > list1 = new ArrayList < String > ();
try {
    Statement st = con.createStatement();
    ResultSet rs = st.executeQuery("select distinct query,count(*) from user_session where uname='" + session.getAttribute("uname") + "' group by query order by datetime desc");
    while (rs.next()) {

        list1.add(rs.getString("query"));

    }
    ArrayList < String > listdb = new ArrayList < String > ();
    for (int i = 0; i < list1.size(); i++) {
        if (list1.get(i).toUpperCase().startsWith(querystr.toUpperCase())) {

            listdb.add(list1.get(i));


        }
    }
    System.setProperty("wordnet.database.dir", "C:/WordNet-3.0/dict/");

    WordNetDatabase database = WordNetDatabase.getFileInstance();

    for (int i1 = 0; i1 < listdb.size(); i1++) {
        Synset[] synsets = database.getSynsets(listdb.get(i1));
        ArrayList < String > al = new ArrayList < String > ();
        // add elements to al, including duplicates
        HashSet hs = new HashSet();
        for (int i = 0; i < synsets.length; i++) {
            String[] wordForms = synsets[i].getWordForms();
            for (int j = 0; j < wordForms.length; j++) {
                al.add(wordForms[j]);
            }
            //removing duplicates
            hs.addAll(al);
            al.clear();
            al.addAll(hs);
            //showing all synsets
            for (int x = 0; x < al.size(); x++) {
                out.println(al.get(x));
            }
            out.println(synsets[i].getDefinition() + "\n");
        }

    }

}

0 个答案:

没有答案