`

Parameter index out of range (1 > number of parameters, which is 0)

阅读更多
遇到Parameter index out of range (1 > number of parameters, which is 0)怎么办?
2011年05月12日 星期四 23:45

遇到了Parameter index out of range (1 > number of parameters, which is 0) ,检查了很多遍错误。最后终于发现,原来PreparedStatement的sql中?是不能带有'单引号的。谢天谢地...一个很简单的失误,我折腾了4个钟头,忘大家引以为戒啊...

// 查询指定用户
public User_table selOperation(String id) {
   String sql = "select * from user_table where Id='?' ";
   User_table user = null;
   try {
    PreparedStatement pst = (PreparedStatement) AdoOpen.openConn()
      .prepareStatement(sql);
    pst.setString(1, id);
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
     user = new User_table();
     user.setId(rs.getString(1));
     user.setName(rs.getString(2));
     user.setPassword(rs.getString(3));
     user.setOnline(rs.getInt(4));
     user.setQita(rs.getString(5));

    }
    rs.close();
    pst.close();
    //AdoOpen.CloseConn();
   } catch (SQLException e) {
    e.printStackTrace();
   }

   return user;

}






java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3326)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3310)
at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4146)
at ado.User_ADO.selOperation(User_ADO.java:60)
at unit.ProssSeverl.rundom(ProssSeverl.java:95)
at unit.ProssSeverl.regidit(ProssSeverl.java:71)
at unit.ProssSeverl.Dealwith(ProssSeverl.java:43)
at unit.ProssSeverl.service(ProssSeverl.java:36)
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:128)
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:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


原来:


String sql = "select * from user_table where Id='?' ";


?不可以加单引号 改为


String sql = "select * from user_table where Id=? ";
分享到:
评论
4 楼 q630077728 2016-03-11  
感谢楼主
3 楼 rj1989y 2012-10-21  
3q
2 楼 javarock 2012-06-13  
果然我也遇到了这个问题了 悲催!!!
1 楼 jiucool 2011-09-21  
引用
[img][/img][url][/url][flash=200,200][/flash]

相关推荐

    MySQL 数据库 like 语句通配符模糊查询小结

    MySQL 报错:Parameter index out of range (1 > number of parameters, which is 0)——MySQL 数据库 like 语句通配符模糊查询小结 前言 今天在使用MySQL语句执行增删改查操作时,控制台报出了以下错误:Parameter...

    Mabatis错误提示Parameter index out of range的处理方法

    在上面的示例中,错误信息显示为"Parameter index out of range (1 > number of parameters, which is 0)",这表明参数索引超出了范围。解决方法是检查参数索引,确保参数索引从1开始。 Parameter index out of ...

    错误总结.doc

    1. **javax.servlet.ServletException: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)**:这个错误通常发生在SQL查询中,当你尝试绑定一个参数,但实际的参数列表为...

    BobBuilder_app

    In this version I have done away with the b+tree and hash index in favor of my own MGIndex structure which for all intents and purposes is superior and the performance numbers speak for themselves....

    二级减速器课程设计说明书reducer design specification.doc

    2, the transmission ratio range of the expanded two-stage gear reducer ia=8 ~ 40, the transmission ratio range of v-belt transmission is ib=2~4, so the theoretical transmission ratio range is=16~160....

    Handbook of Research on Soft Computing and Nature-Inspired Algorithms

    Featuring comprehensive coverage on a range of topics and perspectives such as swarm intelligence, speech recognition, and electromagnetic problem solving, this publication is ideally designed for ...

    Ulam’s searching game with.pdf

    The analysis is based on a generalized version of the game, where the single parameter \( n \) is replaced by a sequence of non-negative integers \( x_0, x_1, \ldots, x_k \). These sequences ...

    i-vector的工具箱

    As expected there is no change in overall shape of the distribution, and only the dynamic range of the feature stream is modified. wcmvn Purpose Cepstral mean and variance normalization (CMVN) ...

    《ASP交互网页设计篇》书中源代码

    ' create the list of parameters which should not be maintained MM_removeList = "&index=" If (MM_paramName <> "") Then MM_removeList = MM_removeList & "&" & MM_paramName & "=" End If MM_keepURL="" MM...

    数位板压力测试

    Out of Bounds Tracking 61 OBT Programming 61 Information Category 61 Turning OBT On and Off 61 B.3. Function Keys 62 FKEYS Programming 62 Information Category 62 B.4. Tilt 62 TILT Programming 63 ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    index (counted from the first index instead of the first list item). - FIX: In THistory.DeleteActions added validation of FActionIndex (FActionIndex could appear beyond the list boundaries). Thanks ...

    occam一维反演

    c ITER00 is a copy of the startup file at iteration 0. Any ITER file can be re- c named startup to continue an inversion. c c As the response of the model in dm() is not necessarily the response of ...

    微软内部资料-SQL性能优化2

    A stack is an area of memory in which program procedure or function call addresses and parameters are temporarily stored. In Process To run in the same address space. In-process servers are loaded ...

    S7A驱动720版本

    logical name of the driver device, which is requested, must be entered . Example: "!switch:D11" delivers the state of the driver device with the name "D11". This function is also available via ...

    WPTools.v6.29.1.Pro

    + There is an overloaded LoadFromString which expects a WideString as parameter (Delphi 6+) - The Setup named the Delphi 2009 files "Delphi 2005" due to a typo. (Delphi 2005 units are not included any...

    BURNINTEST--硬件检测工具

    number of Network Addresses specified in Preferences->Network will be the number of NICs tested. This will error faulty NICs that are not detected by the BurnInTest auto NIC detection mechanism. ...

    VclZip pro v3.10.1

    - By defining ZLIB121, VCLZip will use the latest version of ZLib which is included with the registered version. Some optimization improvements which should show some improvement in zipping and ...

    apktool documentation

    // pkgId of framework-res.apk determines number (which is 0x01) $ apktool if com.htc.resources.apk I: Framework installed to: 2.apk // pkgId of com.htc.resources is 0x02 $ apktool if ...

    servlet2.4doc

    Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. destroy() - Method in class javax.servlet.GenericServlet Called by the servlet container to ...

Global site tag (gtag.js) - Google Analytics