[英]How can I check if the input is in database?
my JFrame cancels the ticket.我的 JFrame 取消了票。 I let the user input the ticket id which is stored in the database and phone number and that happened but my question is how can I check if this ticket is in a database or not !
我让用户输入存储在数据库中的票证 ID 和电话号码,这发生了,但我的问题是如何检查这张票证是否在数据库中! please if you know
请如果你知道
here is my code这是我的代码
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String Ticket_ID=CardNumberTF.getText();
String phone=CardNumberTF1.getText();
if(Ticket_ID.isEmpty()&& phone.isEmpty()){
JOptionPane.showMessageDialog(null, "Please full the fields ");}
else if(Ticket_ID.isEmpty() || phone.isEmpty()){
JOptionPane.showMessageDialog(null, "Please full the empty field ");}
try{
con=DriverManager.getConnection(URL,"iau","iau");
prepared=con.prepareStatement("Delete from BOOKING_INFO WHERE ID_TICKET=? AND PHONE_NUM=?");
prepared.setString(1,Ticket_ID );
prepared.setString(2,phone );
prepared.executeUpdate();
JOptionPane.showMessageDialog(null,
"deleted","delete",JOptionPane.PLAIN_MESSAGE);
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,
"we don't have this ticket id", "Failed",JOptionPane.ERROR_MESSAGE);
System.out.print(ex);
}
private void connect(){
try{
con=DriverManager.getConnection(URL, "iau","iau");
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,ex);
}}
Same as you are doing your delete statement
prepared=con.prepareStatement("Delete from BOOKING_INFO WHERE ID_TICKET=? AND PHONE_NUM=?");
与您执行
delete statement
相同prepared=con.prepareStatement("Delete from BOOKING_INFO WHERE ID_TICKET=? AND PHONE_NUM=?");
, for example: , 例如:
boolean ticketExists = false;
prepared=con.prepareStatement("Select * BOOKING_INFO WHERE ID_TICKET=? AND PHONE_NUM=?");
prepared.setString(1, Ticket_ID);
prepared.setString(2, phone)
ResultSet result = prepared.executeQuery();
while (result.next()) {
// this means that there is ticket, because the result is NOT NULL
// set ticketExists to true
ticketExists = true;
}
` `
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.