<form method="post" name="f1" action="CustomerAddServlet">
<label>姓名:</label><input type="text" name="CustomerName">
<label>电话:</label><input type="text" name="Phone">
<label>手机:</label><input type="text" name="CellPhone">
<label>地址:</label><input type="text" name="Address">
<input type="submit" value="添加">
</form>
String sql="insert into Sales_Customer(CustomerName,Phone,CellPhone,Address,ModifiedDate) values(?,?,?,?,?)";
String customerName=request.getParameter("CustomerName");
String phone=request.getParameter("Phone");
String cellPhone=request.getParameter("CellPhone");
String address=request.getParameter("Address");
Dao dao = new Dao();
Connection conn=dao.getConnection();
PreparedStatement ps=conn.prepareStatement(sql);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
Date now = new Date();//获取当前时间
String ModifiedDate=df.format(now);
ps.setString(1,customerName);
ps.setString(2,phone);
ps.setString(3,cellPhone);
ps.setString(4,address);
ps.setString(5,ModifiedDate);
int row=ps.executeUpdate();
if(row>0){
System.out.println("成功添加");
}
ps.close();
conn.close();
除了表里主键CustomerID自增长和ModifiedDate有值,其他都是null·为什么啊?
SQL JSP
------解决方案--------------------
调试看下 获取的值 是否为空
------解决方案--------------------
conn.commit
需要提交