Java GUI,数据库排序信息

时间:2015-03-02 17:32:30

标签: java database jtable

我在JTable中排序信息时遇到了问题,这是在netbeans中自动生成的。基本上,当你运行它时,它将显示数据库中的所有信息,我无法弄清楚如何对其进行排序。

@NamedQuery(name = "Messages.findAll", query = "SELECT m FROM Messages m"),
@NamedQuery(name = "Messages.findById", query = "SELECT m FROM Messages m WHERE m.id = :id"),
@NamedQuery(name = "Messages.findByRecipient", query = "SELECT m FROM Messages m WHERE m.recipient = :recipient"),
@NamedQuery(name = "Messages.findBySender", query = "SELECT m FROM Messages m WHERE m.sender = :sender"),
@NamedQuery(name = "Messages.findByPriority", query = "SELECT m FROM Messages m WHERE m.priority = :priority"),
@NamedQuery(name = "Messages.findByLabel", query = "SELECT m FROM Messages m WHERE m.label = :label"),
@NamedQuery(name = "Messages.findByMessage", query = "SELECT m FROM Messages m WHERE m.message = :message"),
@NamedQuery(name = "Messages.findBySubject", query = "SELECT m FROM Messages m WHERE m.subject = :subject")})

这是一些代码。所以我需要找出如何为特定收件人排序信息。我一直在textArea中做同样的事情,它正在工作。

    public static String listAll() {
    String output = listHeader();
    try {
        String user = "student@university.ac.uk";
        ResultSet res = stmt.executeQuery("SELECT * from STUDENT.MESSAGES where recipient = '" + user + "'");

        while (res.next()) { // there is a result
            output += formatListEntry(res);
        }
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
    return output;
}

但是如何在Jtable中实现它却无法得到它。这样做了几个星期。

0 个答案:

没有答案