Home > database >  How do I overcome the auto-number row when trying to add a column to a Microsoft access table throug
How do I overcome the auto-number row when trying to add a column to a Microsoft access table throug

Time:01-17

For a project, I have GameNPCID as an auto-number in Access. I can't figure out how to add a set of values to the table, while letting the auto-number primary key handle itself. The primary key in this is called GameNPCID and there are two foreign keys: GameID and NPCID.

String sql = "INSERT INTO GameNPCLink ( NPCFirstName, NPCMood, GameID, NPCID, NPCAge, Life) VALUES (?,?,?,?,?,?)";

        PreparedStatement preparedStatement = con.prepareStatement(sql);

        preparedStatement.setString(1, nPCfirstName);
        preparedStatement.setInt(2, nPCMood);
        preparedStatement.setInt(3, GameID);
        preparedStatement.setInt(4, nPCID);
        preparedStatement.setInt(5, nPCAge);
        preparedStatement.setInt(6, life);

Obviously, this is not the way to do it, but if anyone could lend me a hand that would be great.

I have tried various ways of changing numbers and variables but implementing access in java is quite new to me and I can't seem to find any tutorials online. (Also, if someone knows good tutorials, that would be helpful)

CodePudding user response:

Exclude GameNPCID from the field list and also one parameter (question mark).

Then pass the remaining field values as you do, though adjust the index of these.

  • Related