SQL语句:
String?sql?=?"select?top???*?from?bbs_posts?where?p_fid=??order?by?p_addtime?desc";
????????prepStmt?=?conn.prepareStatement(sql);
????????prepStmt.setInt(1,?xxx);
????????prepStmt.setInt(2,?xx);
????????prepStmt.executeQuery()
预编译:
Exception:
java.sql.SQLException:?'@P0'?附近有语法错误。
????at?net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
????at?net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
????at?net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
????at?net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
????at?net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
????at?net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:777)
????at?yixun.wap.db.DBConnection.executeQuery(DBConnection.java:41)
????at?yixun.wap.bbs.dao.ForumDAO.get500WANforum(ForumDAO.java:282)
????at?yixun.wap.bbs.BbsCache.get500WANforumCache(BbsCache.java:91)
????at?yixun.wap.bbs.service.ForumBO.get500WANforum(ForumBO.java:143)
????at?_jsp._page._bbs._space._second__jsp._jspService(_second__jsp.java:83)
原因:sql不支持为select top ? 预编译,换成动态拼接
String?sql?=?"select?top?%s?*?from?bbs_posts?where?p_fid=??order?by?p_addtime?desc";
????????sql?=?String.format(sql,?num);