【发布时间】:2015-05-26 03:07:22
【问题描述】:
我正在尝试使用下面的脚本将 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);
}
%>
【问题讨论】:
-
我们可以看到您发送到服务器的 URL 吗?更好的是,自己检查一下。我赌 1000 Stack Overflow 点数,您将传递
null值。
标签: mysql jsp jdbc forms http-post