java.sql.SQLException: '@P0' 附近有语法错误
String sql = "select top ? * from bbs_posts where p_fid=? order by p_addtime desc";
预编译:
Exception:
java.sql.SQLException: '@P0' 附近有语法错误。
原因:sql不支持为select top ? 预编译,换成动态拼接.@P0指的是第一个参数附近有错误,要是在第二个参数(?)附近,则错误为'@P1' 附近有语法错误。
String sql = "select top %s * from bbs_posts where p_fid=? order by p_addtime desc";
sql = String.format(sql, num);
sql = String.format(sql, num);
参考:http://www.blogjava.net/jzone/articles/305388.html
http://hi.baidu.com/wenli158/blog/item/6553123314d7f759ac4b5f35.html
---------------------------------------------------------------------------------------------------------------------------------
copyright:http://www.cnblogs.com/anee/