• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

Using servlets to Insert some values in Ms Access db?

Let say you have three fields in a database and one of the fields hold the primary key. Now you want to add two values of the other fields using servlets such that the primary key is automatically added automatically(i.e auto- number) with each an every record added for the two fields.Coz I am encounting errors like the destination fields are not equal when i send the two fields excluding the primary key.

When I assign a null value to a primary key this is what I get

Cannot connect java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] You tried to assign the Null value to a variable that is not a Variant data type.
  • 2
1 Solution
What database are you using. Most databases allow you to specify a field as 'identity' with auto-increment. This means that the value of the field gets set by the DBMS when you insert new rows.
when you write to the db leave the primary key field null.


example: insert into something one, two, three values "null", "something", "something"

Where one is your pk.

Yust specify fields into the statemet, for example if you have three fields fOne,fTwo,fThree and fOne is primary key (I suppose it is autoincremental in Access), then you don't specify this field into statement nor send null value for this field. So the statemet is:

ISERT INTO MyTable fTwo,fThree VALUES(value2,value3);

The points, thank you!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now