I have a Java software to read/write on MySql database. I need to write a query or java method to insert new entry in the follow table:
CREATE TABLE ARTICOLI(CODARTICOLO int NOT NULL,
CodaRTFornitore VARCHAR(13),
CODICEFORNITORE INT,
CODICEBARRE VARCHAR(13),
PREZZOULTIMOACQUISTO DECIMAL(9,2),
PREZZOMEDIO DECIMAL(9,2),
ultimaqtaacquistata int,
FOREIGN KEY(CODARTICOLO) REFERENCES ARTICOLIDETT(CODARTICOLO)
ON DELETE CASCADE
ON UPDATE RESTRICT,
FOREIGN KEY(CODICEFORNITORE) REFERENCES FORNITORI(CODFORNITORE)
ON DELETE CASCADE
ON UPDATE RESTRICT
);
with out PRIMARY KEY.
This is the sample Entry for codarticolo = 5825
:
Now I have a list of BarCode (field CODICEBARRE
). I need to write a java method or MySql query to add new BarCode (field CODICEBARRE
) only if for the same CODARTICOLO
there isn't the new BarCode.
For example, if I have a list with the follow barcode:
8007413739499
0000000000001
0000000000002
I should to ADD two new Entry for CodArticolo = 5825
.
How can I do it in efficiently?