how do you add a row to a child table by entering a row at the parent table automatically?
like doing two insert at once?
Printable View
how do you add a row to a child table by entering a row at the parent table automatically?
like doing two insert at once?
do you mean insert something into two JTables onscreen at once? Or into two database tables at once?
Uhm, a trigger?
i would say directly to a database, a mysql db to be exact.Quote:
do you mean insert something into two JTables onscreen at once? Or into two database tables at once?
like I have to tables name as customers and account. the customers table would hold customer info, and the account table would hold a primary key 'coming from the customers table' and some info about his account. so if I would add a customer, he would automatically have an account.
not really sure what is a trigger, but for the child table maybe.Quote:
Uhm, a trigger?
adding a row at customers table(parent table) would trigger the insertion of a row at the account table(child)
A trigger is a DB thing. Ask about them at a db forum for your db of choice.
Edit: In any case, your code knows if it is inserting a record, so why don't you simply use a transaction, insert both rows, and then commit.
ok, i will try to hit them dudes at the db forum. but what I am after is the primary key that would be created. I would like that to be inserted to a cell in a child table, would that be possible with transactions?
Then see the API docs for Connection and PreparedStatement. You can create a PreparedStatement in such way as to be able to retreive the newly generated ids.
ok, (for the second time) thanks masijade :D