Parameter index out of range(java)

来源:百度知道 编辑:UC知道 时间:2024/06/22 03:01:48
public boolean Delete(int id){
boolean falg = false;
LinkedDB linked = new LinkedDB();
Connection conn = linked.getConMysql();
PreparedStatement stmt = null;
ResultSet rs = null;
String sql ="delete usertable where id=?";
try {
stmt = conn.prepareStatement(sql);
stmt.setInt(1, id);
stmt.executeUpdate();
falg = true;
} catch (Exception e) {
e.printStackTrace();
}
linked.close(conn, stmt, rs);
return falg;
}
这是我的源代码,报错是com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id=13' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
有能回答的朋友麻烦说一下错误的原因,以及应该怎么改正,谢谢!

你的数据库语句错误,我现在身边也没有mysql
你试试把 sql 改成 delete from usertable where id=?

String sql ="delete usertable where id=?";
这句改成:
String sql ="delete usertable where id='?'";
试下

天外游 是对的