我的sql更新语句在eclipse里报附近有语法错误,但是我把sql语句复制到sqlserver 2005里去试却是正常的,能更新。请问这是什么原因。这是更新语句ps=conn.prepareStatement(
"update Bbs_Post set PostLastBackUserId=(select top 1 AssId  from tbl_Assistant,Bbs_PostBack where" +
"tbl_Assistant.UserName=Bbs_PostBack.PostBackSender and PostBackSender=" +
"(select top 1 PostBackSender from Bbs_PostBack,Bbs_Post" +
"where Bbs_PostBack.PostBackPostId=Bbs_Post.PostId and PostId="+id
+"order by PostBackId desc)order by PostBackId desc)where PostId="+id);

解决方案 »

  1.   

    ps=conn.prepareStatement(
    "update Bbs_Post set PostLastBackUserId=(select top 1 AssId from  tbl_Assistant,Bbs_PostBack where " +
    "tbl_Assistant.UserName=Bbs_PostBack.PostBackSender and PostBackSender= " +
    "(select top 1 PostBackSender from Bbs_PostBack,Bbs_Post " +
    "where Bbs_PostBack.PostBackPostId=Bbs_Post.PostId and PostId="+id
    +"order by PostBackId desc)order by PostBackId desc)where PostId="+id);拼接的时候注意where后面的空格
      

  2.   

    仔细看看where前面好像都少了空格.
      

  3.   


    楼主可以把拼出来的sql 用System.out.println()输出到控制台然后粘到查询分析器里执行一下就看出来了
      

  4.   

    建议你在eclipse的console中打印出这个语句,
    System.out.println(sql);
    你就会发现错误的地方了.
      

  5.   

    那证明SQL语句没有问题 是你JAVA里面的问题啊