Integrity constraint violation MS ACCESS: NOT NULL constraint;

<%@ page import="java.sql.*" %>
<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">
    </select> <br>
    <input type="submit" value="Submit">


String n = request.getParameter("userName");
String p = request.getParameter("password");
String e = request.getParameter("email");
String c = request.getParameter("language");

try {


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...");   


} catch (Exception e2) {



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



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" >




All Articles