if a java object has a auto-increment ID field, should the Database table field should be auto-increment as well?
for example
public class Company {
private static int countID = 0;
private int companyID;
private String name;
private String email;
private String password;
private List<Coupon> couponsList;
public Company(int companyID, String name, String email, String password, List<Coupon> couponsList) {
this.companyID = companyID+=1;
this.name = name;
this.email = email;
this.password = password;
this.couponsList = couponsList;
}
you can see that the companyID field is generated automatically.
i have created this table in my SQL server
CREATE TABLE `companies` (
`ID` int NOT NULL AUTO_INCREMENT,
`NAME` varchar(200) DEFAULT NULL,
`EMAIL` varchar(200) DEFAULT NULL,
`PASSWORD` varchar(200) DEFAULT NULL,
PRIMARY KEY (`ID`)
how should I connect the Java field (commpanID) to the sql field (ID)?