日期:2014-05-20  浏览次数:20754 次

jsp在查询的时候报错了
ps = conn.prepareStatement("select * from customer");在执行这条语句的时候一切正常输出
//select top ? customercode, customername, phone, address, relationman,other from customer  where customercode  not in(select top ? customercode from customer) 但是执行这条语句却报出下面的错误
//ps.setInt(1,page.getBeginIndex() );  page.getBeginIndex()=0;
//ps.setInt(2,page.getEveryPage() );   page.getEveryPage()=5
rs= ps.executeQuery();


com.microsoft.sqlserver.jdbc.SQLServerException: '@P0' 附近有语法错误。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:283)
at com.BeifengQuote.DaoImpl.CustomerDaoImpl.findCustomerAll(CustomerDaoImpl.java:215)
at com.BeifengQuote.Action.CustomerFindAllAction.execute(CustomerFindAllAction.java:23)
at com.BeifengQuote.Servlet.WebContral.doPost(WebContral.java:57)
at com.BeifengQuote.Servlet.WebContral.doGet(WebContral.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

这是什么错误呀??

------解决方案--------------------
selec top ?这里好像不能使用参数形式
------解决方案--------------------
select top  '"+要设置的条数 +"'