I'm new to java, I'm using netbeans, I create two tables, master table and detail table, detail table has a composite primary key, one of the primary key refer the master table's primary key, when I created a desktop application, the detail parts only show the columns which are not the primary key, after I finished the form, I can't insert any new record by pressing the 'New' key, so I created a dialog form for detail table, however, I don't know how to bind detail table primary key properly, when I run the code, the primary key of detail table always have null value.

anyone can help me to fix it?



Hm, I don't use NetBeans so I can only advise that you make sure the primary keys in the table are set to auto-increment.

Also, if the New key worked when the primary key columns were visible on the form, just make them invisible, keeping them on the form. Otherwise, you have to link this New key button to the primary through the SQL code behind the New key button.

To bind the key to the table, it should have properties where you can link it to the table and database name, similar to Microsoft Access, which is the only this I can refer from with not having NetBeans in front of me.

Personally, I would code the connection to the database and table with the SQL code behind the new key but look around for the properties. Also try creating the form if NetBeans automatically generates these binds according to your input.