add database Tablenames to the JList in java
// 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.getDatabaseTab开发者_开发知识库leNames();
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.
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?
精彩评论