Claude De-Tchambila :
J'ai essayé de créer trois tables (clients, véhicules et locations), la troisième table (location) a des clés étrangères faisant référence aux deux clés primaires des deux premières tables (clients et de la location). Lors de la création de cette troisième table , je reçois une erreur colonnes manquantes en relation (rel = CLIENTS [[]] -> LOCATION [[]])
Voici mes codes
private void createTables() throws SQLException {
Statement statement = conn.createStatement();
statement.executeUpdate("CREATE TABLE CUSTOMERS(custNumber AUTOINCREMENT PRIMARY KEY, " +
"firstName VARCHAR(155) NOT NULL, surname VARCHAR(155) NOT NULL, idNum INTEGER NOT NULL, phoneNum INTEGER NOT NULL, canRent BIT NOT NULL)");
statement.executeUpdate("CREATE TABLE VEHICLES(vehNumber AUTOINCREMENT PRIMARY KEY, make VARCHAR(155) NOT NULL, " +
"category VARCHAR(155) NOT NULL, rentalPrice FLOAT NOT NULL, availableForRent BIT NOT NULL)");
statement.executeUpdate("CREATE TABLE RENTALS(rentalNumber AUTOINCREMENT PRIMARY KEY, dateRental VARCHAR(155) NOT NULL, dateReturned VARCHAR(155) NOT NULL, " +
"pricePerDay FLOAT NOT NULL, totalRental FLOAT NOT NULL, custNumber INTEGER FOREIGN KEY REFERENCES CUSTOMERS(custNumber), " +
"vehNumber INTEGER FOREIGN KEY REFERENCES VEHICLES(vehNumber))");
System.out.println("Database populated");
}
Votre aide sera très appréciée, je l'ai regardé autour, mais rien trouvé qui aide.
Gord Thompson:
Dans Access, un champ NuméroAuto (DDL: AUTOINCREMENT
ou COUNTER
) est un « Entier long ».
Dans UCanAccess DDL, INTEGER
crée un champ « entier » (16 bits) et LONG
crée un champ « Entier long » (32 bits).
Vous devez déclarer vos colonnes clés étrangères LONG
, non INTEGER
.