添加女神失败
creat_user不知道?什么鬼。。在控制层不是设置女神的creat_user了么,然后传给了模型层。求大神解答
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'create_user' in 'field list'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:882)
at com.imooc.dbo.GoddessDao.addGoddess(GoddessDao.java:36)
at com.imooc.action.GoddessAction.add(GoddessAction.java:17)
at com.imooc.view.View.main(View.java:98)
新增女神失败
view层的新增女神
if(OPERATION_ADD.equals(in.toUpperCase())
||OPERATION_ADD.substring(0, 1).equals(in.toUpperCase())
||OPERATION_ADD.equals(prenious)){
prenious=OPERATION_ADD;
//新增女神
if(1==step){
System.out.println("请输入女神的[姓名]");
}else if(2==step){
goddess.setUser_name(in);
System.out.println("请输入女神的[年龄]");
}else if(3==step){
goddess.setAge(Integer.valueOf(in));
System.out.println("请输入女神的[生日],格式如:yyyy-MM-dd");
}else if(4==step){
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd");
Date birthday=null;
try {
birthday = sf.parse(in);
goddess.setBirthday(birthday);
System.out.println("请输入女神的[邮箱]");
} catch (ParseException e) {
e.printStackTrace();
System.out.println("您输入的格式有误,请重新输入");
step=3;
}
}else if(5==step){
goddess.setEmail(in);
System.out.println("请输入女神的[手机号]");
}else if(6==step){
goddess.setMobile(in);
try {
action.add(goddess);
System.out.println("新增女神成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("新增女神失败");
}
}
控制层Goddessaction的添加女神
public void add(Goddess goddess) throws SQLException{
GoddessDao dao=new GoddessDao();
goddess.setSex(1);
goddess.setCreate_user("ADMIN");
goddess.setUpdate_user("ADMIN");
goddess.setIsdel(0);
dao.addGoddess(goddess);
}
模型层GoddessDao的添加女神
public void addGoddess(Goddess g) throws SQLException{
Connection conn=DBUtil.getConnection();
String sql=" insert into imooc_goddess "+
" (user_name,sex,age,birthday,email,mobile, "+
" create_user,create_date,update_user,update_date,isdel) "+
" values( "+
" ?,?,?,?,?,?,?,current_date(),?,current_date(),?) ";
PreparedStatement psmt = conn.prepareStatement(sql);
psmt.setString(1, g.getUser_name());
psmt.setInt(2, g.getSex());
psmt.setInt(3, g.getAge());
psmt.setDate(4, new Date(g.getBirthday().getTime()));
psmt.setString(5, g.getEmail());
psmt.setString(6, g.getMobile());
psmt.setString(7, g.getCreate_user());
psmt.setString(8, g.getUpdate_user());
psmt.setInt(9, g.getIsdel());
psmt.execute();
}