Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to compare the input data with the data in the database in java-mysql programming; If they are equal, it means that the data already exists and cannot be inserted.
How to compare the input data with the data in the database in java-mysql programming; If they are equal, it means that the data already exists and cannot be inserted.
Make a judgment before inserting into the database.

Boolean ifExists = false

String insertUser,strSql = " select user from emp

stmt . execute update(SQL);

while( stmt.next){

if(insertuser . equals(stmt . getstring(" user ")){

ifExists = true

Break;

}

}

If (if it exists) (

System.out.println ("User already exists");

} Otherwise {

string SQL = " insert into EMP values(" "+num+" ')"; stmt . execute update(SQL);

System.out.println ("Congratulations on joining successfully!" );

}