java.sql.SQLException: @P0 附近有语法错误_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > java.sql.SQLException: @P0 附近有语法错误

java.sql.SQLException: @P0 附近有语法错误

 2011/9/14 8:38:36  hypgr  http://hypgr.iteye.com  我要评论(0)
  • 摘要:SQL语句:Stringsql="selecttop?*frombbs_postswherep_fid=?orderbyp_addtimedesc";prepStmt=conn.prepareStatement(sql);prepStmt.setInt(1,xxx);prepStmt.setInt(2,xx);prepStmt.executeQuery()预编译:Exception:java.sql.SQLException:'@P0'附近有语法错误。atnet.sourceforge
  • 标签:

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);

  • 相关文章
发表评论
用户名: 匿名