Link to home
Start Free TrialLog in
Avatar of wbmorapedi
wbmorapedi

asked on

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.
Avatar of pellep
pellep
Flag of Sweden image

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.
Avatar of cxj97c
cxj97c

and,
when you write to the db leave the primary key field null.

i.e.

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

Where one is your pk.

ASKER CERTIFIED SOLUTION
Avatar of msterjev
msterjev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The points, thank you!