。。问题如标题~~~怎么解决!!!
  在线等~~~~为什么我问的问题 都没人帮我解决的了呢!!!!![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
)

解决方案 »

  1.   

    要向标识列中插入显示值,set IDENTITY_INSERT orders ON
      

  2.   

    代码中,
    在插入数据之前,set IDENTITY_INSERT orders ON
    数据插入完后,set IDENTITY_INSERT orders OFF
      

  3.   

    conn=new ConnDB().getConnection();
    pstmt=conn.prepareStatement("insert into orders (odersId,userId,totalPrice) values (?,?,?)");
    pstmt.setString(1,ID);
    pstmt.setByte(2, (byte)0);
    pstmt.setFloat(3, mubc.returnallprice());
      应该放在哪里呢~~~ 以上是我插入数据的代码段!
      

  4.   


    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 ");
      

  5.   

    问题 还是没解决到哦!!!
      我把代码发给你看!!

    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 ");
      

  6.   


    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();
      

  7.   

    楼上的哥哥 。。按照你的方式改出现了如下的错误!
    INSERT 语句与 COLUMN FOREIGN KEY 约束 'fk_client_id' 冲突。该冲突发生于数据库 'xxx',表 'uers', column 'ID'。
      

  8.   

    是不是users表id为1的记录不存在?
      

  9.   

    在hibenater的配置文件中把id的配置改成 <generator class="native" />
      

  10.   

    请问13楼  hibenater的配置文件在哪?
      

  11.   

    呵呵   我的也是这个错<generator class="native" /> 谢谢了