我有一个用于向数据库插入一些值的 jsp 页面。刷新页面时将重复值插入到数据库表中。如何防止这种情况发生?
try {
//here all values are retrieve using request.getParameters
if(sage!=null) { age=Integer.parseInt(sage); }
if(contact!=null) { phone=Long.parseLong(contact); }
db.connect();
int res=0;
String sql="insert into phr_login(name,address,age,phone,email,username,password,salt,category)values('"+name+"','"+address+"',"+age+","+phone+",'"+emailId+"','"+userId+"','"+epassword+"','"+salt+"','"+category+"')";
if(name!=""&&userId!=""&&password!=""&&emailId!="") {
res=db.updateSQL(sql);
}
}