感谢您的宝贵时间
我收到错误,因为我的项目有 2 个模块添加驱动程序和添加卡车,我正在为这两个模块执行 sql 查询,但是当我执行 addDriver 模块的查询时,数据库异常抛出,说明
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT INTO truck(TRegnNo,VendorName,PurchaseDate,Price,RepairDate,InvoiceNo,RepairCost) VALUES(?,?,?,?,?,?,?)]; Column 'TRegnNo' cannot be null; nested exception is com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Column 'TRegnNo' cannot be null
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
驱动程序插入sql语句public void insertData(Driver driver) { String sql = "INSERT INTO driver"+ "(DLNo,DName,年龄,经验) VALUES (?,?,?,?)"; JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update(sql, new Object[] {driver.getLicenseNumber(),driver.getDriverName(),driver.getAge(),driver.getExperience()});
} Truck Insert code public void insertData(Truck truck)
{
String sql = "INSERT INTO truck" + "(TRegnNo,VendorName,PurchaseDate,Price,RepairDate,InvoiceNo,RepairCost) VALUES(?,?,?,?,?,?,?)";
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.update(sql , new Object[] {truck.getTregNo(),truck.getVendorName(),truck.getPurchaseDate(),truck.getPrice(),truck.getRepairDate(),truck.getInvoiceNo(),truck.getRepairCost()});
}
最佳答案
列TRegnNo
不能为空。您必须为此行分配一个(唯一的)值。
关于java - SPRING MVC数据库jdbc错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24379332/