我面临着java.sql.SQLException:参数索引超出范围(3 > 参数数量,即 2)。更新一列或两列时'重置信息'表有五列(id、mobile_tower_id、reset_value、date_time、clientip)。
'id' 是自动生成的主键。
我想要UPDATE特定行的“reset_value”
现在以下是源代码:
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
String sql = "UPDATE reset_info SET reset_value = ? WHERE id = ?";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, 100);
ps.setInt(3, 1000);
ps.executeUpdate();
conn.close();
以下是我的堆栈跟踪:
Connecting to database...
java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3813)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3795)
at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3840)
at com.mysql.jdbc.PreparedStatement.setInt(PreparedStatement.java:3784)
at cdot.dsa.cfms.dbconnect.NewClass.main(NewClass.java:38)
是否必须为表格的每一列放置占位符('?')?
通过 java.sql.Statement 更新单个列正在工作,但我在 java.sql.preparedStatement 中遇到异常。
请帮忙。概念性想法将受到高度赞赏。
This ps.setInt(3, 1000);
必须是ps.setInt(2, 1000);
因为你只需要占位符。
是否必须为表格的每一列放置占位符('?')?
占位符用于参数而不是列!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)