报错集
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
原因
使用PreparedStatement时,like子句的问号多打了单引号。
String sql = "SELECT * FROM departments WHERE department_name like '?'";
修改
将单引号去掉。
String sql = "SELECT * FROM departments WHERE department_name like ?";
java.sql.BatchUpdateException: Duplicate entry '运营部10' for key 'department_name'
原因
dept = new Departments();没有放到循环中,导致添加的都是同一个对象,触发唯一性约束。
List<Departments> list = new ArrayList<Departments>();
Departments dept = new Departments();
for (int i = 1; i <= 10; i++) {
dept.setDepartmentName("运营部"