0
I’m doing a Java-Desktop Vehicle Rental project. I’m using MVC, DAO and JDBC.
In my bank I have the tables Rental and Car:
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 record in the bank on the Leasing table. I know I have to use the foreign car key(fkcodcarro) somehow, I have researched and tried to do several ways but always keeps giving the same error.
Add the error in your answer, helps us understand what is happening
– leofontes
What did you mean by 'capturing more than one attribute from.... '? What error are you getting? How are you trying to do that Sert? Edit your question and post it all.
– Reginaldo Rigo
My boss, I think you’ll have to perform a Select according to Car FK and recover those values, but, this is not ideal. What’s the point of doing that?
– Alisson
Gnt error is this: Cannot add or update a Child Row : a Foreign key Constraint fails ('fleet'. 'location'), CONSTRAINT 'fk_locacao_carro1' FOREIGN KEY ('fkcodcarro') REFERENCES 'car' ('idcarro'))
– Bianca Reis