首页 > 解决方案 > 使用 Java 检查 MySQL 数据库中的用户已存在时出错

问题描述

我尝试了一些代码来检查用户在注册时是否已经存在于数据库中。但我收到这样的错误。我怎么了?

我正在使用 Netbeans 8.2、Apache Tomcat 和 MySQL 数据库 (XAMPP)。

这是我的registration.jsp页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
  <!DOCTYPE html>
  <html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Registration JSP Page</title>
    <style>
      body {
        background-color: lightblue;
      }
      
      #wgtmsrnew {
        width: 153px;
      }
    </style>
    <script>
      function validateForm() {
        alert("User Registered Successfully");
        return true;
      }
    </script>


  </head>

  <body>
    <form method="post" action="registrationJSPScript.jsp" onsubmit="return validateForm()">
      <center>
        <table border="1" width="30%" cellpadding="5">
          <thead>
            <tr>
              <th colspan="2">Register</th>
              <p><b>Please fill in this form to create an account.</b></p>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>Z ID</td>
              <td><input type="text" name="zid" value="" required="" /></td>
            </tr>
            <tr>
              <td>First Name</td>
              <td><input type="text" name="fname" value="" required="" /></td>
            </tr>
            <tr>
              <td>Last Name</td>
              <td><input type="text" name="lname" value="" required="" /></td>
            </tr>
            <tr>
              <td>Mail ID</td>
              <td><input type="email" name="mailid" value="" required="" /></td>
            </tr>

              <td>Password</td>
              <td><input type="password" name="pass" required="" value="" pattern="^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*_=+-]).{8,12}$" required title="8 characters minimum,At least 1 Uppercase,At least 1 Lowercase,At least 1 number,At least 1 Symbol, symbol allowed --> !@#$%^&*_=+-"
                /></td>
            </tr>
            <tr>
              <td><input type="submit" value="Submit" /></td>
              <td><input type="reset" value="Reset" /></td>
            </tr>
            <tr>
              <td colspan="2">Already registered!! <a href="loginJSP.jsp">Login Here</a></td>
            </tr>
          </tbody>
        </table>
      </center>
    </form>
  </body>

  </html>

标签: javamysqljsp

解决方案


使用 try-catch 块。它会工作。


推荐阅读