我在做java的数据库编程,遇到了一个问题
我是把数据库中的数据显示放到Jtable中的。数据库有两个,比如database_A,database_B。用JcomboBox来选择。问题是:database_A数据已经显示在Jtable中了,如何把database_A的数据清除,然后把database_B的数据放到Jtable中?Jtable的实现我是这样做的:tablemodel 继承abstracttablemodel
然后 tablemodel model =new tablemodel(vector); (vector是传过来的数据库的内容。)Jtable table=new Jtable(model);
用JcomboBox如何监听?急啊!
我是把数据库中的数据显示放到Jtable中的。数据库有两个,比如database_A,database_B。用JcomboBox来选择。问题是:database_A数据已经显示在Jtable中了,如何把database_A的数据清除,然后把database_B的数据放到Jtable中?Jtable的实现我是这样做的:tablemodel 继承abstracttablemodel
然后 tablemodel model =new tablemodel(vector); (vector是传过来的数据库的内容。)Jtable table=new Jtable(model);
用JcomboBox如何监听?急啊!
如果是JList类的话,使用removeAll()方法;
model.setColumnCount(0);
model.setRowCount(0);
然后就可以重新向table中添加新的数据
比如
model.addColumn(新的列名)
model.addRow(新的数据)我以前上数据库这门课的时候做的实验就是这么做的,完全可行
感谢diannaomingong(电脑民工)!感谢兄弟们!