如何使用SpringMVC检查电子邮件是否已在MYSQL数据库中注册?
我也试试
public boolean exists(String email) throws SQLException {
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/Spring3", "root", "root");
Statement st=conn.prepareStatement("select * from Registration");
ResultSet rs=st.executeQuery("select * from Registration");
while (rs.next()) {
if (email.equals(rs.getString("email"))) {
System.out.println("Email already registerd!!");
return true;
}
}
return false;
}
答案 0 :(得分:0)
...
PreparedStatement st=conn.prepareStatement("select * from Registration where email='"+email+"'");
ResultSet rs=st.executeQuery();
if (rs.next()) {
System.out.println("Exists!");
}
else{
System.out.println("Does Not Exist!");
}
...