Results 1 to 8 of 8
  1. #1
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default how to add rows to a child table automaticall

    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?

  2. #2
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    do you mean insert something into two JTables onscreen at once? Or into two database tables at once?

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Uhm, a trigger?

  4. #4
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    do you mean insert something into two JTables onscreen at once? Or into two database tables at once?
    i would say directly to a database, a mysql db to be exact.
    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.

    Uhm, a trigger?
    not really sure what is a trigger, but for the child table maybe.

    adding a row at customers table(parent table) would trigger the insertion of a row at the account table(child)

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    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.

  6. #6
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

    Default

    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?

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    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.

  8. #8
    kulangotski is offline Senior Member
    Join Date
    Feb 2009
    Posts
    117
    Rep Power
    0

Similar Threads

  1. insert multiple rows in the table from List
    By Bulelakes in forum JDBC
    Replies: 2
    Last Post: 11-15-2010, 01:19 PM
  2. Replies: 1
    Last Post: 01-08-2010, 06:19 AM
  3. Replies: 1
    Last Post: 04-23-2009, 07:55 PM
  4. Updating Displayed Table Rows
    By raycini in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 04-20-2009, 08:24 AM
  5. Color cells and rows in SWT table
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-11-2008, 04:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •