我在netbeans中使用jTable。選擇組合框後,如果我選擇了員工ID 1,它將在jTable中顯示emp 1的所有數據。但是,當我選擇emmployee ID 2 JTable的下一次顯示EMP id爲1的單值及以下如何在jTable中顯示數據在JAVA中附加舊值
Connect c = new Connect();//connection to database
con = (Connection) c.getConnection();
st = (Statement)con.createStatement();
String ddate = (String)text.getSelectedItem();
System.out.println("id " +ddate);
rs = st.executeQuery("select e.employee_id,e.`first_name`, i.outtime, i.outtime_date from tbl_employee e,tbl_outtime i where e.employee_id=i.outtime_emp_id and i.`outtime_date` LIKE '%/"+month2+"/"+year1+"'and outtime_emp_id="+ddate);
while(rs.next())
{
String dat1=rs.getString("outtime_date");
String e1=rs.getString("employee_id");
System.out.println(e1);
st33=(Statement) con.createStatement();
rs33=st33.executeQuery("select i.intime, i.intime_date from tbl_employee e,tbl_intime
i where e.employee_id=i.intime_emp_id and i.`intime_date`='"+dat1+"' and
i.intime_emp_id="+e1);
if(rs33.next())
{
int emp=rs.getInt("employee_id");
System.out.println(emp);
String name=rs.getString("first_name");
String dept=rs33.getString("intime");
String desig=rs.getString("outtime");
String join=rs33.getString("intime_date");
jTable1.setValueAt(emp, cnt, 0);
jTable1.setValueAt(name, cnt, 1);
jTable1.setValueAt(dept, cnt, 2);
jTable1.setValueAt(desig, cnt, 3);
jTable1.setValueAt(join, cnt, 4);
cnt=cnt+1;
}
}
我的代碼被賦予EMPID 2. 所有其他值告訴我解決辦法,如果有人知道。
很難說任何切肉刀,爲更好的幫助儘早發佈[SSCCE](http://sscce.org/) – mKorbel
oky,但你能告訴我,我可以清除jTable,而點擊組合框 – Amruta
table.setModel(new YourTableModel ()); – MadProgrammer