感谢您的时间Spring MVC的数据库错误JDBC
我正在为我的项目有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语句公共无效insertData(驱动程序驱动程序) { 字符串的sql = “INSERT INTO司机” +“(DL号,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”不能null'。您试图为具有非空约束的数据库列设置空值 – geoand
错误“*列”TRegnNo'不能为空*“对我来说很清楚。 –
例外清楚地说'列'TRegnNo'不能为空' – Sadikhasan