我的SQL报异常:java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
下面是我的SQL语句:String sql="select * from product where mprice bettwean ? and ? , cname like '%?%' ";请高手帮下忙看看哪里错了!

解决方案 »

  1.   

    已经很明确了,你SQL写了3个问号,但参数只传了二个进去
      

  2.   

    SQL明显也有错!仔细检查,小问题
      

  3.   

    有两个错:
    1.和1楼说的,你的SQL中写了3个问号,需要传入3个参数,可能你只传了2个;
    2.你的SQL中的between写错了。
      

  4.   

    select * from product where mprice bettwean ? and ? , cname like '%?%' 
    改成select * from product where mprice between ? and ? and cname like '%?%' 
    3个?号需要传入3个参数。
      

  5.   

    select * from product where mprice bettwean ? and ? , cname like '%?%'  
    like 写法错误select * from product where mprice bettwean ? and ? , cname like ?
    like的值要写成ps.setString("%查询值%")
      

  6.   

    问题解决要结贴的
    有两个错:
    1.和1楼说的,你的SQL中写了3个问号,需要传入3个参数,可能你只传了2个;
    2.你的SQL中的between写错了。
      

  7.   

    你的sql语句需要传三个参数,你只传了两个
      

  8.   

    我传的是三个参数啊,为啥我写成cname like '%?%',然后psmt.setString(1,"a");就报异常
    String sql="select * from product where (cname like '%?%') and (mprice between 10 and 100)";
    conn=db.getConnection();
    psmt=db.getPreparedStatement(sql);


    try {
    psmt.setString(1, c);
    psmt.setFloat(2, 10);
    psmt.setFloat(3, 100); rs=db.getResultSet(psmt);
      

  9.   

    是不是cname like '%?%',不能用?号啊
      

  10.   

    cname like ??= \‘+"%" \’+参数 + \‘+"%" \