views:

43

answers:

2
// Declare JList
private JList jlstTab, jlstCol;
.
.
.
DefaultListModel dlmTables = new DefaultListModel();
DefaultListModel dlmCol = new DefaultListModel();

        // Instantiate 
        dlmTables.addElement("kl");
        jlstTab= new JList(dlmTables);
     jlstTab.setSelectedIndex(0);
        jlstTab.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

.
.
.
.

//Connect to the database
public static void main(String args[])
    {
   DBToolSwing cs = new DBToolSwing("DB Tool Swing");
   try


                  DBAccessObject dbAccess1 = new DBAccessObject("jdbc:odbc:JavaClassDSN");
          DBAccessObject dbAccess2 = new DBAccessObject();
                  ResultSet rsTables = dbAccess1.getDatabaseTableNames();
          while (rsTables.next())
          System.out.println(rsTables.getString("TABLE_NAME"));

I need to get the table names from the database, the output shouldn't be printed on the screen, instead I need the output added to the JlstTab so dlmTables.addElement("TABLE_NAME"); Please if someone can help I would appreciate it. Thanks in advance.

A: 

Assuming both snippet is working for you. I mean you are able to print the table names on the console, and you are also able to show some fixed value in your JList. So, why not, instead of System.out.println(rsTables.getString("TABLE_NAME")) use dlmTables.addElement(rsTables.getString("TABLE_NAME")). Where is the problem?

Adeel Ansari
A: 

Thanks for your respond, however result are not displayed in the JList, keep getting an error. "Variable dmlTables location class DBToolSwing". What I did is that in the constructor "DBToolSwing" I have instantiated the JList and then in the void method I'm trying to add a code to add the table name to JList. I know there is something wrong, not sure about. Please your input is very important to me. Thank you for your time. Hope to hear from you.

litecia