Java 在表之间建立关系以更新详细信息

Java 在表之间建立关系以更新详细信息,java,jdbc,Java,Jdbc,我有两个表,即USR_表和USR_配置文件 USR_TBALE有以下列: ID(主键) 全名 电子邮件 用户状态 密码 在用户配置文件表中: ID(引用用户表的外键)和主键 用户状态 公司 角色 在用户表中,我以编程方式插入userId(使用javauuid)、全名、电子邮件、用户状态和密码 我的问题是,当我在USR_表中插入ID时,我是否必须在USR_概要文件表中自动插入相同的ID以保持ID值不变 如果是这样,我如何在java中做到这一点 现在我的代码是: 注册地址: public class

我有两个表,即USR_表和USR_配置文件

USR_TBALE有以下列:

  • ID(主键)
  • 全名
  • 电子邮件
  • 用户状态
  • 密码
  • 在用户配置文件表中:

  • ID(引用用户表的外键)和主键
  • 用户状态
  • 公司
  • 角色
  • 在用户表中,我以编程方式插入userId(使用javauuid)、全名、电子邮件、用户状态和密码

    我的问题是,当我在USR_表中插入ID时,我是否必须在USR_概要文件表中自动插入相同的ID以保持ID值不变

    如果是这样,我如何在java中做到这一点

    现在我的代码是:

    注册地址:

    public class RegistrationDAO {
    
        public int insert(UserProfile user) {
    
            int count  = 0;
            try {            
                String uniqueID = UUID.randomUUID().toString();
    
                Connection con = DBConnection.getConnection();
                String query = "insert into TBL_USER (USR_ID, USR_FULL_NAME,USR_PRIMARY_EMAIL,USR_PASSWORD,USR_STATUS) values(?,?,?,?,?)";
                PreparedStatement pst = con.prepareStatement(query);
    
                pst.setString(1, uniqueID);
                pst.setString(2, user.getFullName());
                pst.setString(3, user.getEmail());
                pst.setString(4, user.getPassword());
                pst.setString(5, "PENDING");
                count  = pst.executeUpdate();
            } catch (Exception e) {
                System.out.println("@@@@Record insertion error in Registration DAO@@@@");
                e.printStackTrace();
            }
            return count;
        }
    }
    
    个人资料:

    public class ProfileDAO {
    
        public void SaveProfile(UserProfile userProfile) {
            Connection con = null;
            try {
                con = DBConnection.getConnection();
                String query = "Insert into TBL_USER_PROFILE (USR_SUMMARY, USR_ROLE, USR_COMPANY, USR_FROM, USR_TO, USR_LOCATION) VALUES(?,?,?,?,?,?)";
                PreparedStatement pst = con.prepareStatement(query);
                pst.setString(1, userProfile.getSummary());
                pst.setString(2, userProfile.getRole());
                pst.setString(3, userProfile.getCompany());
                pst.setString(4, userProfile.getFrom());
                pst.setString(5, userProfile.getTo());
                pst.setString(6, userProfile.getLocation());
                pst.executeUpdate();
    
            } catch (Exception e) {
                System.out.println("Error in Profile DAO class in method SaveProfile()");
                e.printStackTrace();
            }
        }
    }
    

    是-这些值需要匹配。你是说你在事后更改了主键用户ID吗?这是个坏主意…@Randy我不明白你说的“你是说你在事后更改了主键用户ID”是什么意思