日期:2014-05-18  浏览次数:20750 次

请高手们指定一二,JSP数据库插入的问题,明明没有插入相同的主键,为什么总是提醒我违反了 PRIMARY KEY 约束 'PK_T_USER'。不能在对象 'T_U
插入代码如下:
//执行数据库注册用户信息
public   void   createuserinfo()throws   Exception
{
      String   reg= "insert   into   T_USER   values(?,?,?,?,?,?,?,?,?) ";
try
    {  
    PreparedStatement   pstmt=conn.prepareStatement(reg);          
            pstmt.setString(1,userInfo.getUID());
    pstmt.setString(2,userInfo.getUPASSWORD());
    pstmt.setString(3,userInfo.getEMAIL());
    pstmt.setString(4,db.getStr(userInfo.getUSERNAME()));
    pstmt.setInt(5,userInfo.getSEXID());
    pstmt.setInt(6,userInfo.getBIRTH_YEAR());
    pstmt.setInt(7,userInfo.getBIRTH_MON());
    pstmt.setInt(8,userInfo.getBIRTH_DATE());
    pstmt.setInt(9,0);
    int   n=pstmt.executeUpdate();
    System.out.println(n);
    System.out.println( "用户名是: "+userInfo.getUID());
            System.out.println( "密码是: "+userInfo.getUPASSWORD());
            System.out.println( "姓名是: "+db.getStr(userInfo.getUSERNAME()));
            System.out.println( "EMAIL是: "+userInfo.getEMAIL());
            System.out.println( "性别是: "+userInfo.getSEXID());
            System.out.println( "出生年份是: "+userInfo.getBIRTH_YEAR());
            System.out.println( "出生月份是: "+userInfo.getBIRTH_MON());
            System.out.println( "出生日期: "+userInfo.getBIRTH_DATE());
}
catch(Exception   e)
{
System.out.println(e);
throw   e;
}
conn.close();
      }


JSP调用此处理过程如下:
<%@   page   language= "java "     buffer= "none "   import= "java.util.* "   pageEncoding= "UTF-8 "%>
<jsp:useBean   id= "userInfo "   class= "cn.UserInfo "   scope= "session ">
<jsp:setProperty   name= "userInfo "   property= "* "/>
</jsp:useBean>
<jsp:useBean   id= "user "   class= "cn.Usermanager "   scope= "page "/>
<%
    String   ID=request.getParameter( "UID ");    
    boolean   d=user.isuserexist(ID);
    try{
    if(d)
    {    
            user.setUserInfo(userInfo);
    user.createuserinfo();
    response.sendRedirect( "index.html ");
      }
    else
    {  
          response.sendRedirect( "regist.html ");
    }
    }catch(Exception   e){e.printStackTrace();}  
%>


------解决方案--------------------
System.out.println( "密码是: "+userInfo.getUPASSWORD());
System.out.println( "姓名是: "+db.getStr(userInfo.getUSERNAME()));