0

I am trying to INSERT INTO one column in MySQL database. When trying to do this, I get an error for "No default value" on an entirely different column in the DB. Why would this be if I'm not trying to insert anything into the column I'm getting the error for?

Query being used with JdbcTemplate from Spring Framework:

String sql = "INSERT INTO database_1(col1) VALUES(?)";
jdbc.batchUpdate(sql, params);

params is also populated with legitimate parameters

Output from console: INSERT INTO database_1(col_1) VALUES(?)]; Field 'col_2' doesn't have a default value; nested exception is java.sql.BatchUpdateException

Wyatt
  • 31
  • 7

1 Answers1

0

Some columns in a table may require a value, that is, null values are not allowed. If so, a default value can be specified for the column when the table is created. If you insert a new row in the table without specifying a value for that column, the default value will be used. If no such value was specified when the tables was created you will get the error you got. You either need to specifiy a default value for the column when creating the table, or provide one when inserting a new row.

Roger Gustavsson
  • 1,689
  • 10
  • 20