。。问题如标题~~~怎么解决!!!
在线等~~~~为什么我问的问题 都没人帮我解决的了呢!!!!![Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'orders' 中的标识列插入显式值。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
我的表创建如下:
create table orders(
odersId bigint primary key identity(1,1),
userId bigint constraint fk_client_id references uers(ID),
orderDate datetime default getdate(),
payMode varchar(20) check (payMode in('货到付款','支付宝付')) default '货到付款',
isPayed bit check (isPayed in (0,1)),
totalPrice float not null
)
在线等~~~~为什么我问的问题 都没人帮我解决的了呢!!!!![Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'orders' 中的标识列插入显式值。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeUpdateInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeUpdate(Unknown Source)
我的表创建如下:
create table orders(
odersId bigint primary key identity(1,1),
userId bigint constraint fk_client_id references uers(ID),
orderDate datetime default getdate(),
payMode varchar(20) check (payMode in('货到付款','支付宝付')) default '货到付款',
isPayed bit check (isPayed in (0,1)),
totalPrice float not null
)
在插入数据之前,set IDENTITY_INSERT orders ON
数据插入完后,set IDENTITY_INSERT orders OFF
pstmt=conn.prepareStatement("insert into orders (odersId,userId,totalPrice) values (?,?,?)");
pstmt.setString(1,ID);
pstmt.setByte(2, (byte)0);
pstmt.setFloat(3, mubc.returnallprice());
应该放在哪里呢~~~ 以上是我插入数据的代码段!
conn=new ConnDB().getConnection();
Statement stmt = conn.createStatement();
stmt.execute("set IDENTITY_INSERT orders ON ");
pstmt=conn.prepareStatement("insert into orders (odersId,userId,totalPrice) values (?,?,?)");
pstmt.setString(1,ID);
pstmt.setByte(2, (byte)0);
pstmt.setFloat(3, mubc.returnallprice());
pstmt.executeQuery();
stmt.execute("set IDENTITY_INSERT orders OFF ");
我把代码发给你看!!
conn=new ConnDB().getConnection();
Statement stmt = conn.createStatement();
stmt.execute("set IDENTITY_INSERT orders ON ");
pstmt=conn.prepareStatement("insert into orders (odersId,userId,totalPrice) values (?,?,?)");
pstmt.setString(1,ID);
pstmt.setByte(2, (byte)0);
pstmt.setFloat(3, mubc.returnallprice());
int a=pstmt.executeUpdate();
stmt.execute("set IDENTITY_INSERT orders OFF ");
Statement stmt = conn.createStatement();
pstmt=conn.prepareStatement("insert into orders (userId,totalPrice) values (?,?)");
pstmt.setByte(1, (byte)0);
pstmt.setFloat(2, mubc.returnallprice());
int a=pstmt.executeUpdate();
INSERT 语句与 COLUMN FOREIGN KEY 约束 'fk_client_id' 冲突。该冲突发生于数据库 'xxx',表 'uers', column 'ID'。