开发者

Can any one tell me what is wrong with PrepareStatement syntax

public ResultSet readSubSet(int No, String name, String case) throws SQLException {
    preparedStatement = connect.prepareStatement("SELECT *  FROM target WHERE myName=? AND myCase=? LIMIT ?,10")开发者_高级运维;
    preparedStatement.setString(8, name);
    preparedStatement.setString(6, case);
    preparedStatement.setInt(1, No);
    resultSet = preparedStatement.executeQuery();   
    return resultSet;
}

After run I got: java.sql.SQLException: Parameter index out of range (8 > number of parameters, which is 2).

my table define myName and myCase is TEXT, is that ok I use prepareStatement.setString


When you call setString you pass in two arguments, the first is the index of the parameter you are filling in and the second is the value you are filling it with. In your case, you would want prepareStatement.setString(1,name); to fill in the 1st parameter, prepareStatement.setString(2,case); to fill in the 2nd parameter, and so on.


In your SQL you only have 3 variables and you are setting variable 8 as name in preparedStatement.setString(8, name)...

Look @ http://download.oracle.com/javase/tutorial/jdbc/basics/prepared.html#supply_values_ps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜