I have one database that has two tables.
One table (Table A) has 3 columns:
idpms serial NOT NULL,
iduser integer NOT NULL,
iduser2 integer NOT NULL,
And the other (Table B) 3 columns
idmessage serial NOT NULL,
idpms integer NOT NULL,
text character varying(255),
I’m using Java to manage my database.
First, table A is updated with the values of user one and user two.
With the idpms values generated when I insert this data, Table B is updated with idpms and text
I have two questions:
-
How can I retrieve the value of
idpmsafter inserting data in Table A? -
In Java, can I somehow extract the
idpmsand cast it to an int?
Q1 :Yes.
Q2 :Yes.
Serial is just
autoincrementing integerThere is no special command to get the value after insert you can use sql queries for it.
If you want to get value before insert then
This articlediscusses about it I hope you get what you want