2014-06-24 52 views
0

感谢您的时间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()}); 


}      
+1

您堆栈跟踪包含'列“TRegnNo”不能null'。您试图为具有非空约束的数据库列设置空值 – geoand

+0

错误“*列”TRegnNo'不能为空*“对我来说很清楚。 –

+0

例外清楚地说'列'TRegnNo'不能为空' – Sadikhasan

回答

1

TRegnNo不能为空。您必须为此行分配一个(唯一)值。

+0

但我没有在卡车表中输入。我添加了一个新的驱动程序,然后为什么它给我一个'TRegNo'的错误,因为它们在该名称的驱动程序表中没有列。 – user3480311

+0

看来,当你添加一个驱动程序,它会触发卡车表的这个其他SQL。看看你的数据库管理器是否有这样的触发器。 – Paul

+0

您好保罗我已经分享了我的代码添加驱动程序并添加卡车modules.Please提供您的可变的反馈。 – user3480311

0

退房这个:

堆栈跟踪包含Column 'TRegnNo' cannot be null指向约束在卡车表,如主键或外键等。