Java.sql.SQLException: Field "provider_id" has no default value

I got an error message:

java.sql.SQLException: Field 'supplier_id' doesn't have a default value at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3277) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1402) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1317) 

Anyone can help me? My database fields are not empty. but I want to get the following results:

insert into xxx(name,password)values('xxx','xxx'); and insert into xxx(name,password,man)values('xxx','xxx','xxx'); both successes (both in the client - success, but there is an error in the java code, the error code is in the upper header), instead of insert into xxx(name,password)values('xxx','xxx') - false; my mysql jar - mysql-connector-java-5.0.8

+8
java sql mysql
source share
6 answers

The mistake itself. Your column supplier_id does not have a default value. Therefore, during the insertion, mysql cannot understand what needs to be inserted into the supplier_id column. You can do one of three: -
1. Add a default value to the supplier_id column. Using -

 ALTER TABLE `xxx` ALTER `supplier_id` SET DEFAULT NULL 


2. Put some value in the supplier_id column during insertion.
3. Add the automatic increment to the column and add the primary key to it using the code: -

 ALTER TABLE `xxx` CHANGE `supplier_id` `supplier_id` INT(10)AUTO_INCREMENT PRIMARY KEY; 
+17
source share

To solve this problem, either set the value to supplier_id when you execute INSERT , or make the column nullable in the database.

+2
source share

Added this property.

 <property name="hbm2ddl.auto">create</property>. 

Worked for me

+1
source share

You are using a table that has an id_ provider column. it does not have a default value; when entering time, this column does not receive any value. initialize the vend_id column with some default value or use auto-increment if you use the provider_id as the primary key.

0
source share

Two cases are possible.

  • You specified the default value for the column as NONE and do not paste any value to it when pasting.

  • You declared a column in the database, but you did not declare the same in the object of the object that causes the error.

0
source share

Maybe this is a problem with the table schema. drop the table and run the application again.

0
source share

All Articles