我在DAO层中用下面的嵌套sql语句查询怎么是返回false呢?不懂,请大家帮忙!我在mysql命令行下执行是正确的!
file表中的sortId和sort表中的id字段关联。        sql = "update sort set number = number-1 where id = (select sortId from file where id = ? )";
dbc.prepareStatement(sql);
dbc.setLong(2, id);
if(dbc.executeUpdate() == 0) {
return false;

解决方案 »

  1.   

    number = number-1这个表达式是什么意思呢,它是放在""里面,是被当成字符串看待的,应该是不能进行运算的
      

  2.   

    我测试了下,如果用一个值代替number-1的话还是不行的。到底是啥问题呢?
      

  3.   

    dbc.setLong(2, id);那只能是这里错了.
      

  4.   

    dbc.setLong(2, id); 
    不知道你的代码是不是全copy过来了,为甚么是“2”呢?
    我记得这里的数字代表的是第几个问号“?”;sql = "update sort set number = number-1 where id = (select sortId from file where id = ? )";
    而你的sql里面只有一个问号啊
    是不是应该
    dbc.setLong(1, id); 还有调用prepareStatement(sql)的应该是一个连接Connection!
    而调用setlong()方法的应该是一个preparedStatement的实例!
    你全部用的“dbc“,  dbc是什么呢?假如参数为Connection  dbc; PreparedStatement pstmt = null;
     sql = "update sort set number = number-1 where id = (select sortId from file where id = ? )";
        pstmt = dbc.prepareStatement(sql);
        dbc.setLong(1, id);
        if(dbc.executeUpdate() == 0) {
            return false;
        } 
      

  5.   

    因为copynide代码!我的上一个回答有误    pstmt.setLong(1, id); 
       
      

  6.   

    dbc.setLong(2, id);
    好奇怪的2啊!1在哪里啊?