使用数据库时,设置了主键和外键,是不是应该先插入包含主键的数据表,再插入外键的数据表?新手求指点
现在用的是先插包含外键的数据表,报错如下,'data_id'是外键,还有data列,id列为自增。此为插入语句insertintodatas(data)values(?)...
现在用的是先插包含外键的数据表,报错如下,'data_id'是外键,还有data列,id列为自增。
此为插入语句insert into datas(data) values(?)
com.microsoft.sqlserver.jdbc.SQLServerException: 不能将值 NULL 插入列 'data_id',表 'udpygxy.dbo.datas';列不允许有 Null 值。INSERT 失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:308)
at CommandData.DataCl.DataClcode(DataCl.java:27)
at CommandData.CommandHeadUtil.Decodebytes(CommandHeadUtil.java:52)
at CommandData.CommandHeadUtil.Save(CommandHeadUtil.java:77)
at ThreadPool.ControlThread.execute(ControlThread.java:50)
at ThreadPool.WorkThread.run(WorkThread.java:19) 展开
此为插入语句insert into datas(data) values(?)
com.microsoft.sqlserver.jdbc.SQLServerException: 不能将值 NULL 插入列 'data_id',表 'udpygxy.dbo.datas';列不允许有 Null 值。INSERT 失败。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(SQLServerPreparedStatement.java:308)
at CommandData.DataCl.DataClcode(DataCl.java:27)
at CommandData.CommandHeadUtil.Decodebytes(CommandHeadUtil.java:52)
at CommandData.CommandHeadUtil.Save(CommandHeadUtil.java:77)
at ThreadPool.ControlThread.execute(ControlThread.java:50)
at ThreadPool.WorkThread.run(WorkThread.java:19) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询