Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我会收到这个MySQLIntegrityConstraintViolationException:Column';名字';发布此脚本时不能为null?_Mysql_Jsp_Jdbc_Forms_Http Post - Fatal编程技术网

为什么我会收到这个MySQLIntegrityConstraintViolationException:Column';名字';发布此脚本时不能为null?

为什么我会收到这个MySQLIntegrityConstraintViolationException:Column';名字';发布此脚本时不能为null?,mysql,jsp,jdbc,forms,http-post,Mysql,Jsp,Jdbc,Forms,Http Post,我正试图使用下面的脚本将html表单数据插入我的数据库,但在运行应用程序时,我收到以下错误消息: 错误..com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: 列“first_name”不能为空 我做错了什么:/ <% Connection con = null; PreparedStatement st = null; String

我正试图使用下面的脚本将html表单数据插入我的数据库,但在运行应用程序时,我收到以下错误消息:

错误..com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: 列“first_name”不能为空

我做错了什么<代码>:/

  <%
        Connection con = null;  
        PreparedStatement st = null;

        String first_name = request.getParameter("first_name");
        String last_name = request.getParameter("last_name");
        String phone = request.getParameter("phone");
        String email = request.getParameter("email");
        String address_1 = request.getParameter("address_1");
        String address_2 = request.getParameter("address_2");
        String city = request.getParameter("city");
        String State_Province_Region = request.getParameter("State_Province_Region");
        String Postal_Zip_Code = request.getParameter("Postal_Zip_Code");
        String country = request.getParameter("Country");


        try {
              con = DriverManager.getConnection("jdbc:mysql://localhost:3306/application","root",
         "password");

              st = con.prepareStatement("INSERT INTO customer (first_name, last_name, phone, email, address_1, address_2, city, State_Province_Region, Postal_Zip_Code, Country) VALUES (?,?,?,?,?,?,?,?,?,?)");


                 st.setString(1,first_name);
                 st.setString(2,last_name);
                 st.setString(3,phone);

                 st.setString(4,email);
                 st.setString(5,address_1);
                 st.setString(6,address_2);

                 st.setString(7,city);
                 st.setString(8,State_Province_Region);
                 st.setString(9,Postal_Zip_Code);

                 st.setString(10,country);

              st.executeUpdate();
              st.clearParameters(); 



             st.close();
             con.close();
        } 

        catch (Exception e) { 
             out.println("Error.."+e);
        }
%>

我知道这听起来很明显。。。但是数据库中firstname列的设置设置为不允许空值。此外,您必须在其中一行中为该字段传递空值


也许,在那里放置一个断点,以捕获在填充请求变量后实际的sql命令。

尝试放置
System.out.println()
语句,并调试
名字、姓氏等的值

其他错误的事情: 1将所有JDBC代码移动到一个单独的Java文件中
2个close()语句应位于finally块中。如果出现异常,它们不会在您的情况下执行。

我们可以看到您发送到服务器的URL吗?最好自己检查一下。我打赌1000个堆栈溢出点,您正在传递一个
null
值。