从另一个Frame插入数据后刷新JTable

时间:2018-10-05 05:40:30

标签: java database sqlite

当我打开我的*.mydomain.com并包含带有AdminPanel的{​​{1}}和按钮以打开添加病人的框架时,填写表格后,我点击了添加按钮,将会保存到数据库

JTable

此后,我退出填充有患者记录的框架,并且PatientRecords和包含int YesOrNo = JOptionPane.showConfirmDialog(null, "Do you want to save?", "Save",JOptionPane.YES_NO_OPTION); if(YesOrNo == 0){ try{ String sql = "Insert into Patient_Records (First_Name,Last_Name,MI,Age,Birth_Date,Gender,Marital_Status,Street,City,[State/Province],Zip_Code,Country,Contact_No,Email_Address,Registered_Date,[In/Out]) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; pst = conn.prepareStatement(sql); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String now = (sdf.format(new java.util.Date())); pst.setString(1, ADDFIRSTNAME.getText()); pst.setString(2, ADDLASTNAME.getText()); pst.setString(3, ADDMIDDLEINITIAL.getText()); pst.setString(4, ADDAGE.getText()); pst.setString(5, ((JTextField)ADDDATE.getDateEditor().getUiComponent()).getText()); pst.setString(6, (String) ADDGENDERBOX.getSelectedItem()); pst.setString(7, (String)ADDSTATUS.getSelectedItem()); pst.setString(8, ADDADDRESS.getText()); pst.setString(9, ADDADDRESS1.getText()); pst.setString(10, ADDADDRESS2.getText()); pst.setString(11, jTextField3.getText()); pst.setString(12, (String)ADDCOUNTRY.getSelectedItem()); pst.setString(13, jTextField1.getText()); pst.setString(14, jTextField2.getText()); pst.setString(15, now); pst.setString(16, "0"); String CN = jTextField1.getText(); String EA = jTextField2.getText(); String F = ADDFIRSTNAME.getText(); String M = ADDLASTNAME.getText(); String L = ADDMIDDLEINITIAL.getText(); if(!ConValid(CN)){ JOptionPane.showMessageDialog(null, "Contact Number is not valid","Invalid Input",JOptionPane.WARNING_MESSAGE); }else if(!ConValid(CN)){ JOptionPane.showMessageDialog(null, "Contact Number must contain 11 number(s)","Invalid Input",JOptionPane.WARNING_MESSAGE); }else if(!valEmail(EA)){ JOptionPane.showMessageDialog(null, "Invalid Email Address","Invalid Input",JOptionPane.WARNING_MESSAGE); }else if(!OnLetter(F) || !OnLetter(M) || !OnLetter(L)){ JOptionPane.showMessageDialog(null, "Name must not contain number(s)","Invalid Input",JOptionPane.WARNING_MESSAGE); }else{ JOptionPane.showMessageDialog(null, "Saved","Saved",JOptionPane.INFORMATION_MESSAGE); pst.execute(); AdminPortal AP = new AdminPortal(); AP.PatientRec(); } }catch(Exception e){ JOptionPane.showMessageDialog(null, e); } }else{ } 的{​​{1}}确实刷新了

我尝试了此代码

AdminPanel

我该怎么办?

1 个答案:

答案 0 :(得分:0)

这里的表需要用最新数据刷新。为此,请按照以下步骤操作。

  • 保存操作成功完成后,清除JTable实例。
  • 调用用于显示PatientRecords的例程/方法,新的调用将确保JTable实例中反映出最新数据。

在代码方面:

_userRepository.GetAllIncluding(u => u.Claims,
                                u => u.CreatorUser,
                                u => u.DeleterUser,
                                u => u.Roles,
                                u => u.Department).FirstOrDefault(u => u.Id ==loginResult.User.Id);