【发布时间】:2017-05-20 04:00:15
【问题描述】:
为了找出错误,我做了很多搜索工作。我发现许多其他学习者也有同样的错误,但它是针对插入语句的。但是我的问题似乎是在寻找删除语句的问题。我收到以下错误:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [delete from tbl_cust where Cust_id=2]; Parameter index out of range (1 > number of parameters, which is 0).; nested exception is java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
但是,当我在 localhost/phpmyadmin/ 中查询相同的 sql 时,它会删除记录而没有错误 我尝试了以下一些方法:
public int delete(int id) throws ClassNotFoundException, SQLException {
String sql= "DELETE FROM tbl_cust WHERE Cust="+id;
Object[] obj={id};
return JdbcTemplate.update(sql,obj);
}
这是下一个例子
public int delete(int id) throws ClassNotFoundException, SQLException {
String sql= "DELETE FROM tbl_cust WHERE Cust_id=?";
Object[] obj={id};
return JdbcTemplate.update(sql,obj);
}
【问题讨论】:
标签: java mysql spring-mvc jdbctemplate