java - 使用 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>
解决方案
使用 try-catch 块。它会工作。
推荐阅读
- vue.js - Vue2 - 从组件内的主实例调用方法
- python-3.x - 在 QPlainTextEdit (PyQt5) 中为 python 实现自动缩进
- mysql - 如何从 mySQL 浮点列中选择十进制数
- python - 如何使用硒和python点击网页上的所有“角色=按钮”
- quantifiers - Dafny/Boogie 中的触发器是什么?
- mysql - 在具有各种其他条件的 MYSQL 中使用 DISTINCT 时查询缓慢(1000 万条记录)
- php - 当公用文件夹名称为下划线时,链接不起作用,例如 public_html
- service-worker - 拦截 fetch 事件并返回 indexedDB 数据
- octave - Plotting line graph with custom X values
- ruby - 检查答案是否为空