幫忙查找一下錯誤
??? //修改功能
public void updateGodess(Goddess g) throws Exception{
?? ?Connection conn =DBUtil.getConnection();
??? String sql =""
?? ??? ??? ?+ " update imooc_goddess "+
?? ??? ??? ??? ??? ?" (user_name=?,sex=?,age=?,birthday=?,email=?,mobile=?, "
?? ??? ??? ??? ??? ?+" update_user=?,update_date=current_date(),isdel=?) "
?? ??? ??? ??? ??? ?+" where id =? ";
??? PreparedStatement ptmp =? conn.prepareStatement(sql);
??? ptmp.setString(1, g.getUser_name());
??? ptmp.setInt(2,g.getSex());
??? ptmp.setInt(3, g.getAge());
??? ptmp.setDate(4, new Date(g.getBirthday().getTime()));
??? ptmp.setString(5, g.getEmail());
??? ptmp.setString(6, g.getMobile());
??? ptmp.setString(7, g.getUpdate_user());
??? ptmp.setInt(8, g.getIsdel());
??? ptmp.setInt(9, g.getId());
????? ?
??? ptmp.execute();
}
測試代碼
Goddess g1 = new Goddess();
?? ?g1.setUser_name("小月");
?? ?g1.setAge(22);
?? ?g1.setSex(1);
?? ?g1.setBirthday(new Date());
?? ?g1.setEmail("[email protected]");
?? ?g1.setMobile("1234388888");
?? ?g1.setUpdate_user("ADMIN");
?? ?g1.setIsdel(1);
?? ?g1.setId(3);
?? ?//g.addGoddess(g1);
?? ?g.updateGodess(g1);
拋出異常
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 '(user_name='小月',sex=1,age=22,birthday='2016-07-05',email='[email protected]',mo' at line 1
?? ?at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
2017-03-06
+" update_user=?,update_date=current_date(),isdel=?) "你這句多了個)
2016-07-06
你的SQL語句那里寫錯了,換成下面這樣 ?update 表名 ?set 字段1="", 字段2="" ? ? where ?成立的條件