java.sql.SQLException: '@P0' 附近有語法錯誤
Posted on 2009-12-10 11:00 Gavin.lee 閱讀(3571) 評論(1) 編輯 收藏 所屬分類: JDBCSQL語句:
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);





預編譯:
Exception:












原因:sql不支持為select top ? 預編譯,換成動態拼接

