I want to delete a record from database. The code runs fine, but even when there is a record for a particular id, the message returns
id not found in database
. Please help me to improve my code to display a separate message when id is not found in database.i have attached my output. as u can see id=19 i there in database but when i delete id=19, that particular id record gets deleted from the database but message pops up saying id not found in database.
try {
String s = TUID.getText( );
Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/mysql", "root", "root" );
Statement st = con.createStatement( );
String r = "delete from mysql57.addressbook where iid = "+s;
PreparedStatement preparedStatement = con.prepareStatement( r );
preparedStatement.executeUpdate( );
int rows = preparedStatement.executeUpdate();
if(rows == 0)
{ JOptionPane.showMessageDialog( f, "ID NOT FOUND IN DATABASE");
}
else{
JOptionPane.showMessageDialog( f, "DELETED FROM DATABASE" );
}
}
}
catch (Exception ex) {
JOptionPane.showMessageDialog( f,ex );
}