验证部分出现问题,没有关于空字段的消息显示。立即提供帮助
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");
}
}
江户川乱折腾
慕村225694
相关分类