Name:

Integrity constraint violation MS ACCESS: NOT NULL constraint;

<%@ 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>

      

Every time I run this code in Eclipse the following message appears in the console, but my database is updated

net.ucanaccess.jdbc.UcanaccessSQLException: integrity constraint violation: NOT NULL check constraint; SYS_PK_10174 table: USERDETAILS column: NAME

      

+3


source to share


1 answer


You insert into the database on page load before submitting the form. Thus, the parameters null

. You should set the attribute action

to a different page or better servlet which should do the updates via java and sql code execution and then redirect to the view page. You don't need values null

to insert into the database because the constraint is allowed to exclude values null

.



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

      

+1


source







All Articles