java.sql.SQLException:字段"supplier_id"没有默认值 [英] java.sql.SQLException: Field 'supplier_id' doesn't have a default value
问题描述
我收到一条错误消息:
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)
每个人都可以帮助我吗? 我的数据库字段不为空. 但我想得到这个结果:
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');
两者都成功(在客户端中都是成功,但是在Java代码中是error,错误代码位于标题的顶部),而不是insert into xxx(name,password)values('xxx','xxx')
是false;
我的mysql jar是mysql-connector-java-5.0.8
insert into xxx(name,password)values('xxx','xxx');
and 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
推荐答案
该错误不言自明.您的列supplier_id
没有默认值.因此,在插入期间,mysql无法找出要在列supplier_id
中插入的内容.您可以做以下三件事之一:-
1.将默认值添加到supplier_id
使用-
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 -
ALTER TABLE `xxx` ALTER `supplier_id` SET DEFAULT NULL
2.在插入过程中为supplier_id
列提供一些值.
3.在该列中添加一个自动增量,并使用以下代码向其添加主键:-
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;
这篇关于java.sql.SQLException:字段"supplier_id"没有默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!