我在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;
}
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;
}
不知道你的代码是不是全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;
}
好奇怪的2啊!1在哪里啊?