将数据库表名添加到java中的JList中
// 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"));
我需要从数据库获取表名,输出不应打印在屏幕上,而是需要将输出添加到 JlstTab 所以 dlmTables.addElement("TABLE_NAME"); 如果有人可以帮助我,我将不胜感激。提前致谢。
// 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设这两个片段都适合您。我的意思是您可以在控制台上打印表名称,并且还可以在 JList 中显示一些固定值。那么,为什么不使用
dlmTables.addElement(rsTables.getString("TABLE_NAME")) 来代替 System.out.println(rsTables.getString("TABLE_NAME"))
。问题出在哪里?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"))
usedlmTables.addElement(rsTables.getString("TABLE_NAME"))
. Where is the problem?