Error updating database.
Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value
名为id类型的属性值没有默认值,可能是在创建表单的过程中没有将id设置为主键自增长类型(在写入数据设置id为主键自增长类型)

public class Student {
private Integer id;//使用Intger可以进行非空判断if(id==null)
private String name;
private int age;
private double score;
public Student() {
}
public Student( String name, int age, double score) {
this.name = name;
this.age = age;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public String toString() {
return "Student{" +
"id=" + id +
", name=‘" + name + ‘\‘‘ +
", age=" + age +
", score=" + score +
‘}‘;
}
}
public class MyTest {
/*测试类*/
private IStudent iStudent ;
@Before
public void before(){
iStudent = new IStudentIMP();//多态(接口)
}
@Test
public void testInsert(){
Student student = new Student("张三",24,88.8);
iStudent.insertStu(student);
}
在上传数据至数据库时没有设置id的值)
原文:https://www.cnblogs.com/-star/p/13406633.html