chendurex chendurex - 2 years ago 117
SQL Question

java.sql.SQLException: Field 'supplier_id' doesn't have a default value

I got an error message from this:

java.sql.SQLException: Field 'supplier_id' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(
at com.mysql.jdbc.MysqlIO.checkErrorPacket(
at com.mysql.jdbc.MysqlIO.sendCommand(
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(
at com.mysql.jdbc.Connection.execSQL(
at com.mysql.jdbc.Statement.executeUpdate(
at com.mysql.jdbc.Statement.executeUpdate(

Everyone can help me ?
my database fields are not empty .
but i want to get this results:

insert into xxx(name,password)values('xxx','xxx');

insert into xxx(name,password,man)values('xxx','xxx','xxx');

both success (both of that in client is success ,but in java code is error,error code at top title), instead of
insert into xxx(name,password)values('xxx','xxx')
is false;
my mysql jar is mysql-connector-java-5.0.8

Answer Source

The error is self explanatory. Your column supplier_id does not have a default value. So during insertion, mysql cannot figure out what to insert in the column supplier_id. You can do either of the three things :-
1. Add a default value to the column supplier_id Using -


2. Supply some value to the supplier_id column during insertion.
3. Add an auto increment to the column and add a primary key to it using the code :-

ALTER TABLE `xxx` CHANGE `supplier_id` `supplier_id` INT(10)AUTO_INCREMENT PRIMARY KEY;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download