我正在使用Netbeans进行项目,并希望在从JLabel
选择员工时显示JComboBox
上的员工详细信息。
我试过......但对画面没有影响。
private void formWindowOpened(java.awt.event.WindowEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tnpcb","root","");
String sql="select curr_no,receive_date from tapal where user_id='"+jComboBox1.getSelectedItem()+"'";
pst=con.prepareStatement(sql);
rs=pst.executeQuery();
while(rs.next())
{
System.out.println("hi22");
jLabel1.setText(rs.getString("curr_no"));
jLabel1.setText(rs.getString("receive_date"));
}
}
catch(ClassNotFoundException | SQLException e)
{
}
}
答案 0 :(得分:0)
尝试使用try和catch
包围你的代码尝试{ PST = con.prepareStatement(SQL);
rs=pst.executeQuery();
while(rs.next())
{
System.out.println("hi22");
jLabel1.setText(rs.getString("curr_no"));
jLabel1.setText(rs.getString("receive_date"));
}
} catch(例外e){}