Spring mvc 如何使用SpringMVC检查电子邮件是否已在MYSQL数据库中注册?
如何使用SpringMVC检查电子邮件是否已在MYSQL数据库中注册 我也尝试Spring mvc 如何使用SpringMVC检查电子邮件是否已在MYSQL数据库中注册?,spring-mvc,Spring Mvc,如何使用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
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;
}
可能重复的
...
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!");
}
...