为了账号安全,请及时绑定邮箱和手机立即绑定

帮忙查找一下错误

    //修改功能
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("xiaoxai@qq.com");
    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='xiaoxai@qq.com',mo' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

正在回答

2 回答

+" update_user=?,update_date=current_date(),isdel=?) "你这句多了个)

0 回复 有任何疑惑可以回复我~
#1

EKKOY

isdel=?这个后边的)
2017-03-06 回复 有任何疑惑可以回复我~

你的SQL语句那里写错了,换成下面这样  update 表名  set 字段1="", 字段2=""     where  成立的条件

String sql=""+
		      " update imooc_goddess"+
		      " set user_name=?,sex=?,age=?,birthday=?,email=?,mobile=?,"+
		      " update_user=?,update_date=current_date(),isdel=?"+
		      " where id =?";


1 回复 有任何疑惑可以回复我~
#1

连宏伟HW

楼上正解
2016-07-06 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

帮忙查找一下错误

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号