Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JDBC Insert query question

Options
  • 27-11-2011 7:24pm
    #1
    Registered Users Posts: 839 ✭✭✭


    Hi, I'm doing some java and I can do a JDBC insert query to add a row to an mdb table with this line....

    stmt.executeUpdate(INSERT INTO Publications values('6','Name','57')

    The first entry, 6, is what I'm using as the Index or ID field. The problem is that the user isn't concerned with what this is and doesn't know whats a free ID. I'd like to run this INSERT so that simply the next free ID number is used to populate the field - so if there's 17 entries already, the next INSERT will make this field 18. I'd still need to have control over what goes into the other fields.

    I'm not where or how to do this. Is this done at the Java programming end - or at the Access database end?

    Any help much appreciated

    kelbal


Comments

  • Registered Users Posts: 898 ✭✭✭OREGATO


    When setting up your DB, make the PK auto increment.

    This way, when you're doing the insert, you can go INSERT INTO Publications values('Name','57')


  • Registered Users Posts: 839 ✭✭✭kelbal


    Thanks Oregato. I made my primary key field auto increment instead of just number. Had to create new field, make it PK, then delete old one. Then I try to do same INSERT with one less field at start, get this error

    Number of query values and destination fields are not the same

    Is there something else I should be doing?


  • Registered Users Posts: 839 ✭✭✭kelbal


    Don't worry, found the answer. If you want your insertion to start at Field 2 - you have to specify the Field Names just before the 'values' bit, like this......

    INSERT INTO Publications (Name, Age)values('Joe Bloggs','57')


Advertisement