更新女神代码问题
public void updateGoddess(Goddess g) throws SQLException{//更新,数据通过对象的形式传进来 Connection conn=DBUtil.getConnection(); String sql=""+//编写sql语句 "update into goddess set user_name=?,sex=?,age=?,birthday=?,email=?,mobile=?,update_user=?,update_date=current_date(),isdel=? where id=?";//问号为占位符 //prepareStatement方法会将sql语句加载到驱动程序的执行程序中,但不会直接执行,预编译 PreparedStatement ptmt=conn.prepareStatement(sql); //传参给预编译符 ptmt.setString(1, g.getUser_name()); ptmt.setInt(2, g.getSex()); ptmt.setInt(3, g.getAge()); ptmt.setDate(4, new Date(g.getBirthday().getTime()));//因为在原定义方法中Date是java.util类型的,此处需要转换成java.sql类型的 ptmt.setString(5, g.getEmail()); ptmt.setString(6, g.getMobile()); ptmt.setString(7, g.getUpdate_user()); ptmt.setInt(8, g.getIsdel()); ptmt.setInt(9, g.getId()); //当调用execute()才会执行 ptmt.execute(); }
测试数据时代码如下
GoddessDao g=new GoddessDao(); Goddess g1=new Goddess(); g1.setUser_name("小兰"); g1.setAge(21); g1.setSex(1); g1.setBirthday(new Date());//定义为今天,用util类型 g1.setEmail("xiaolan@123.com"); g1.setMobile("15071234567"); g1.setUpdate_user("ADMIN");//更新人 g1.setIsdel(1);//是否删除,否 g1.setId(4); g.updateGoddess(g1);
最后报错
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'into goddess set user_name='小兰',sex=1,age=21,birthday='2017-06-04',email='xi' at line 1
请问是哪里出了问题,求解答,谢谢~