【问题标题】:MS ACCESS integrity constraint violation: NOT NULL check constraint;MS ACCESS 完整性约束违反:NOT NULL 检查约束;
【发布时间】:2014-11-27 10:39:59
【问题描述】:
<%@ 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

【问题讨论】:

    标签: java html sql jsp servlets


    【解决方案1】:

    您在提交表单之前在页面加载时插入数据库。因此参数是null。您应该将action 属性设置为另一个页面或更好的servlet,它应该通过执行java 和sql 代码执行更新,然后重定向到视图页面。您不需要将 null 值插入数据库,因为已启用约束以不允许 NULL 值。

    <form action="yourpage.jsp" method="post" >
    

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 2016-12-13
      • 2020-10-02
      • 2018-03-20
      • 2021-06-10
      • 2021-03-24
      • 1970-01-01
      • 2015-11-01
      • 2020-01-14
      相关资源
      最近更新 更多