说我的SQL语句不对。。package com.tuoluofu.controller;
import java.sql.*;
public class ReSet {

 private Connection conn = null;
 PreparedStatement prepStmt = null;
ResultSet rs = null;
 public ResultSet Select(String aname,String apwd)
 {
 
 conn = new Conne().getCon();
 String sql = "select * from where aname=? and apwd=? ;";
 try {
 prepStmt=conn.prepareStatement(sql);
 prepStmt.setString(1, aname);
 prepStmt.setString(2, apwd);
 rs=prepStmt.executeQuery();
 
 while (rs.next())
 {
 System.out.println(rs.getString("aname"));
 System.out.println(rs.getString("apwd"));
 System.out.println(rs.getString("alever"));
 return rs;
 }
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (rs != null) {
try {
rs.close();
} catch (SQLException e) { e.printStackTrace();
}
}
if (prepStmt != null) {
try {
prepStmt.close();
} catch (SQLException e) { e.printStackTrace();
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) { e.printStackTrace();
}
}
}

 
 return rs ;
 }}
错误信息java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2715)
at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:3546)

解决方案 »

  1.   

    不用占位符试试String sql = "select * from where aname=‘“+aname+”’ and apwd=‘“+apwd+”’ "; 
    然后
    prepStmt=conn.prepareStatement(sql); 
    prepStmt.setString(1, aname); 
    prepStmt.setString(2, apwd); 改成prepStmt=conn.createStatement(sql); 
      

  2.   

    sql 语句有问题
    String sql = "select * from where aname=? and apwd=? ;"; 表名呢  后面还多了个 ‘;’吧
      

  3.   

    String sql = "select * from where aname=? and apwd=? ;"; 
    别的不太清楚啊
    不过好像引号之前没有分号吧。
      

  4.   

    sql文不对,哪有查询后面带;的
    String sql = "select * from where aname=? and apwd=? ;"; 
    去掉第二个?号后的;
      

  5.   

    select * from where aname=? and apwd=? ;" 表名哪去了?