简体   繁体   中英

Java Netbeans DB tables relationship

I am trying to create a Java project using a database.

I have created a database with 3 tables and created a relationship connecting 2 of the tables to other. So Members , Donation and Expenses . Donations and Expenses are connected to Members . I used the following SQL to create the relationship:

ALTER TABLE <TABLE>
    ADD CONSTRAINT TABLE_FK
    FOREIGN KEY (MEMBER_ID)
    REFERENCES MEMBERS (ID); 

When I try and add data to either the Donations or Expenses table I can't because of the connection with Members table: it has a variable <MEMBERS member> instead of <String Member_ID> . How do I add data to the tables or should I just recreate my database?

因此,根据注释中发布的摘录片段,您需要创建一个新的Member对象,或者使用您用来通过POJO与数据库进行接口的任何框架检索现有的Member对象,并假设Member在Donations中不可为空,并使用Donations(假定的)setMember方法填充Member。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM