I'm doing a Java-Desktop Vehicle Lease project. I am using MVC, DAO and JDBC.
In my bank I have the Rental and Car tables:
CREATE TABLE IF NOT EXISTS 'frota'.'carro' (
'idcarro' INT(11) NOT NULL AUTO_INCREMENT,
'chassi' VARCHAR(45) NULL DEFAULT NULL,
'renavam' VARCHAR(45) NULL DEFAULT NULL,
'placa' VARCHAR(45) NULL DEFAULT NULL,
'combustivel' VARCHAR(45) NULL DEFAULT NULL,
'numero_de_portas' INT(11) NULL DEFAULT NULL,
'cor' VARCHAR(45) NULL DEFAULT NULL,
'ano' INT(11) NULL DEFAULT NULL,
'quilometragem' INT(11) NULL DEFAULT NULL,
'valor_locacao' DOUBLE NULL DEFAULT NULL,
'marca' VARCHAR(100) NULL DEFAULT NULL,
'modelo' VARCHAR(100) NULL DEFAULT NULL,
PRIMARY KEY ('idcarro'))
ENGINE = InnoDB
AUTO_INCREMENT = 19
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS 'frota'.'locacao' (
'idlocacao' INT(11) NOT NULL AUTO_INCREMENT,
'fkcodcarro' INT(11) NULL,
'fkcodcliente' INT(11) NULL,
'fkcodfuncionario' INT(11) NULL,
'data_locacao' DATE NULL DEFAULT NULL,
'hora_locacao' TIME NULL DEFAULT NULL,
'data_devolucao' DATE NULL DEFAULT NULL,
'hora_devolucao' TIME NULL DEFAULT NULL,
'tempo' VARCHAR(45) NULL DEFAULT NULL,
'status' VARCHAR(100) NOT NULL,
'taxa' DOUBLE NOT NULL,
PRIMARY KEY ('idlocacao'),
INDEX 'fk_locacao_funcionario1_idx' ('fkcodfuncionario' ASC),
INDEX 'fk_locacao_cliente1_idx' ('fkcodcliente' ASC),
INDEX 'fk_locacao_carro1_idx' ('fkcodcarro' ASC),
CONSTRAINT 'fk_locacao_carro1'
FOREIGN KEY ('fkcodcarro')
REFERENCES 'frota'.'carro' ('idcarro')
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT 'fk_locacao_cliente1'
FOREIGN KEY ('fkcodcliente')
REFERENCES 'frota'.'cliente' ('idcliente')
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT 'fk_locacao_funcionario1'
FOREIGN KEY ('fkcodfuncionario')
REFERENCES 'frota'.'funcionario' ('idfuncionario')
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 15
DEFAULT CHARACTER SET = utf8;
My intention is to write to the bank in the Location table. I know I have to use the car foreign key (fkcodcarro) somehow, I already researched and tried to do it in several ways but it always keeps giving the same error.