首页 > 解决方案 > 如何通过选择 jcombobox 值来填充 jtable

问题描述

我是编程新手。我有一个带有表约会的数据库。表字段医生,患者姓名。我想通过从 jcombobox 中选择医生来使用医生和患者姓名填充 jtable。我在下面尝试过,但在表中只带来了列名,没有数据。没有错误。谢谢。

   try
{
String comboVal=(String)cbox_doctors.getSelectedItem();
String sql1="select doctor, patient_firstname, patient_surname from 
appointments where doctor=?";
pst1=conn.prepareStatement(sql1);
pst1.setString(1, comboVal);
rs1=pst1.executeQuery();

while(rs1.next())
{
table_report.setModel(DbUtils.resultSetToTableModel(rs1));

}
}
catch(Exception e)
{
//JOptionPane.showMessageDialog(null,"error");
System.out.println(e);
} finally {

        try{

            rs1.close();
            pst1.close();

        }
        catch(Exception e){

        }
     }

标签: javasqliteswingjtablejcombobox

解决方案


推荐阅读