0

Thanks for your time

I am getting an error as my project is having 2 modules add driver and add truck for which i am executing the sql query for both but when i execute the query for addDriver module the database exception is throwing stating

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) 

driver insert sql statement public void insertData(Driver driver) { String sql = "INSERT INTO driver" + "(DLNo,DName,Age,Experience) 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()});


}                      
7
  • 1
    You stacktrace contains Column 'TRegnNo' cannot be null. You are trying to set a null value to a DB column that has a non null constraint Commented Jun 24, 2014 at 6:02
  • The error "Column 'TRegnNo' cannot be null" is pretty clear to me. Commented Jun 24, 2014 at 6:02
  • Exception clearly say Column 'TRegnNo' cannot be null Commented Jun 24, 2014 at 6:03
  • But i am not making an entry in truck table. I am adding a new driver then why it is giving me an error of 'TRegNo' as their is no column in it of that name. Commented Jun 24, 2014 at 6:07
  • The stacktrace should be longer than that and at a moment, you should find a line from your sources. Look what happens at that line and show full file or at least some lines around. Commented Jun 24, 2014 at 6:24

2 Answers 2

1

Column TRegnNo can not be null. You have to assign a (unique) value to this row.

Sign up to request clarification or add additional context in comments.

5 Comments

But i am not making an entry in truck table. I am adding a new driver then why it is giving me an error of 'TRegNo' as their is no column in driver table of that name.
It seems that when you add a driver, it triggers this other sql for the truck table. Look in your database manager if there is such a trigger.
Hi paul i have shared my code for add driver and add truck modules.Please provide your vaulable feedback.
Somewhere this method is called: public void insertData(Truck truck). My suggestion is that you debug your code and look into the truck object. The truck.getTRegNo returns null and therefore the error.
I have debugged it and traced the issue that was my mistake. Thank you
0

Check out with this :

StackTrace contains Column 'TRegnNo' cannot be null pointing to constraints in Truck table, like primary key or foreign key etc..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.