如何检查电子邮件是否已使用SpringMVC在MYSQL数据库中注册?

时间:2018-04-13 17:58:01

标签: 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 * 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;

}

1 个答案:

答案 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!");
    }
...