【发布时间】:2019-08-28 04:09:21
【问题描述】:
验证部分的问题,没有关于空字段的消息显示。马上帮忙
private void addbtnActionPerformed(java.awt.event.ActionEvent evt) {
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/dbfinance","root","1234");
String sql="insert into util(type_,due_date,month_,amount,units,status_) values(?,?,?,?,?,?)";
PreparedStatement pstm =con.prepareStatement(sql);
pstm.setString(1,electype.getSelectedItem().toString());
pstm.setString(2,date.getText().toString());
pstm.setString(3,jComboBox1.getSelectedItem().toString());
pstm.setDouble(4,Double.parseDouble(amount.getText()));
pstm.setString(5,unit.getText());
pstm.setString(6,status.getText());
pstm.executeUpdate();
JOptionPane.showMessageDialog(null, "success");
con.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
if(amount.getText().isEmpty()||unit.getText().isEmpty()||status.getText().isEmpty()){
JOptionPane.showMessageDialog(null,"please enter data");
// errorname2.setText("fill this field");
}
}
【问题讨论】:
-
你说的是哪个空域?鉴于您分享的信息有限,我们甚至无法重现您面临的问题,因此无法找到解决方案。
-
在此程序金额文本字段中,单位文本字段和状态文本字段不应为空(用户应填写该字段)。如果为空,应显示消息“请输入数据”。但是问题是没有显示消息。