【发布时间】:2014-04-12 12:56:52
【问题描述】:
我有一个框架,可以添加新的客户信息数据。当我输入现有的customerName 时,我想验证我的JTextField,消息对话框显示“客户名称已存在!”。
这是我将新数据添加到我的数据库表的代码。我应该把那些JTextField 验证码放在哪里?
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
cn.connection();
String sql = "insert into customer(customerName, customerPhone, customerAddress, contactPerson) values('" + customerName.getText() + "','" + customerPhoneTxtField.getText() + "', '"+ textCustomerAddress.getText() +"', '"+contactPersonTxtField.getText()+"')";
ps = cn.con.prepareStatement(sql);
ps.execute();
JOptionPane.showMessageDialog(null, "Customer Successfully Added");
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Fill in the field(s) to complete.", "Error", JOptionPane.ERROR_MESSAGE);
}
}
【问题讨论】:
标签: java swing validation jdbc jtextfield