mardi 29 décembre 2015

Using query to populate JList using the DefaultListModel

I am a Java novice building a multiple Frame TabbedPane application with multiple panels. On one of my one of panels I am using a JList and attempting to populate it using a query.

I am using SQLite as the DB.

private JList<String> listTTSearch;

public void loadList() {
    try {
        String query = "select tt_name from TriTiers";
        PreparedStatement pst = dbConn.prepareStatement(query);
        ResultSet rs = pst.executeQuery();
        DefaultListModel<String> DLM = new DefaultListModel<String>();

        while(rs.next()){
            DLM.addElement(rs.getString("tt_name"));
        }
        listTTSearch.setModel(DLM);
        pst.close();
        rs.close();

    } catch (Exception refreshTable) {

    }
}

No errors are thrown and the JList, listTTSearch is not being populated. Other aspects of my application are working well with the DB.

A similar posts seems to address this issue Java JList and list problems , but does not seem to plausible to fix my issue.

Any assistance or guidance would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire