<%@ page import="java.sql.*" %>
<HTML>
<BODY>
<form method="post" >
Name:<input type="text" name="userName"><br>
Password:<input type="password" name="password"><br>
Email Id:<input type="text" name="email"><br>
Language: <select name="language">
<option>Hindi</option>
<option>English</option>
<option>French</option>
</select> <br>
<input type="submit" value="Submit">
</form>
<%
String n = request.getParameter("userName");
String p = request.getParameter("password");
String e = request.getParameter("email");
String c = request.getParameter("language");
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con= DriverManager.getConnection("jdbc:ucanaccess://D:/eclipse/register.accdb","","");
PreparedStatement ps = con
.prepareStatement("insert into USERDETAILS values(?,?,?,?)");
ps.setString(1, n);
ps.setString(2, p);
ps.setString(3, e);
ps.setString(4, c);
int i= ps.executeUpdate();
if (i > 0) {
out.print("You are successfully registered...");
}
else{
out.println("failed");
}
} catch (Exception e2) {
System.out.println(e2);
}
%>
</BODY>
</html>
每次我在 Eclipse 中运行此代码时,控制台都会出现以下消息,但我的数据库已更新
net.ucanaccess.jdbc.UcanaccessSQLException: integrity constraint violation: NOT NULL check constraint; SYS_PK_10174 table: USERDETAILS column: NAME
最佳答案
在提交表单之前,您将在页面加载时插入数据库。因此参数为 null
。您应该将 action
属性设置为另一个页面或更好的 servlet,它应该通过执行 java 和 sql 代码来执行更新,然后重定向到 View 页面。您不需要将 null
值插入到数据库中,因为已启用约束以不允许 NULL
值。
<form action="yourpage.jsp" method="post" >
关于java - MS ACCESS 完整性约束冲突 : NOT NULL check constraint;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26160861/