Parameter index out of range (1 > A parameters, which is 0)
Source: Internet
Author: User
What to do if you encounter parameter index out of range (1 > # of parameters, which is 0).
May 12, 2011, Thursday 23:45
Parameter index out of range (1 > # parameters, which is 0) was encountered and many errors were checked. Finally found that the original preparedstatement in the SQL. Cannot have ' single quotes '. Thank God... A very simple mistake, I toss 4 head, forget everyone warning ah ...
Query the specified user
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));
Java.sql.SQLException:Parameter index out of range (1 > A 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)
Originally:
String sql = "SELECT * from user_table where id= '?" ";
? instead of adding single quotes to
String sql = "SELECT * from user_table where id=?";
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.