Foreign key dans une TableView
Bonjour,
Voici mon problème :
J'ai une table "Location" qui contient le "Proprietaire" et le "Locataire" qui eux sont des clés étrangères qui font appel aux table Proprietaire et Locataire ( via les ID logique ).
J'aimerais afficher dans une TableView ( deux colonnes ) le nom du Propriétaire et du Locataire, sauf que je ne trouves pas comment faire :/
Voici mon objet Location :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
| package fr.signoret.epreuve4.model;
public class Location {
int id_Location;
int id_Proprietaire;
int id_Locataire;
float loyer;
float charges;
String adresse;
String adresseSuite;
int codePostal;
String ville;
int type;
int nbrPiece;
int nbrSalleBain;
int nbrWC;
String cave;
String garage;
String parking;
String balcon;
float superficieBalcon;
public Location(int id_Location, int id_Proprietaire, int id_Locataire, float loyer, float charges, String adresse,
String adresseSuite, int codePostal, String ville, int type, int nbrPiece, int nbrSalleBain, int nbrWC,
String cave, String garage, String parking, String balcon, float superficieBalcon) {
super();
this.id_Location = id_Location;
this.id_Proprietaire = id_Proprietaire;
this.id_Locataire = id_Locataire;
this.loyer = loyer;
this.charges = charges;
this.adresse = adresse;
this.adresseSuite = adresseSuite;
this.codePostal = codePostal;
this.ville = ville;
this.type = type;
this.nbrPiece = nbrPiece;
this.nbrSalleBain = nbrSalleBain;
this.nbrWC = nbrWC;
this.cave = cave;
this.garage = garage;
this.parking = parking;
this.balcon = balcon;
this.superficieBalcon = superficieBalcon;
}
public int getId_Location() {
return id_Location;
}
public int getId_Proprietaire() {
return id_Proprietaire;
}
public int getId_Locataire() {
return id_Locataire;
}
public float getLoyer() {
return loyer;
}
public float getCharges() {
return charges;
}
public String getAdresse() {
return adresse;
}
public String getAdresseSuite() {
return adresseSuite;
}
public int getCodePostal() {
return codePostal;
}
public String getVille() {
return ville;
}
public int getType() {
return type;
}
public int getNbrPiece() {
return nbrPiece;
}
public int getNbrSalleBain() {
return nbrSalleBain;
}
public int getNbrWC() {
return nbrWC;
}
public String getCave() {
return cave;
}
public String getGarage() {
return garage;
}
public String getParking() {
return parking;
}
public String getBalcon() {
return balcon;
}
public float getSuperficieBalcon() {
return superficieBalcon;
}
public void setId_Location(int id_Location) {
this.id_Location = id_Location;
}
public void setId_Proprietaire(int id_Proprietaire) {
this.id_Proprietaire = id_Proprietaire;
}
public void setId_Locataire(int id_Locataire) {
this.id_Locataire = id_Locataire;
}
public void setLoyer(float loyer) {
this.loyer = loyer;
}
public void setCharges(float charges) {
this.charges = charges;
}
public void setAdresse(String adresse) {
this.adresse = adresse;
}
public void setAdresseSuite(String adresseSuite) {
this.adresseSuite = adresseSuite;
}
public void setCodePostal(int codePostal) {
this.codePostal = codePostal;
}
public void setVille(String ville) {
this.ville = ville;
}
public void setType(int type) {
this.type = type;
}
public void setNbrPiece(int nbrPiece) {
this.nbrPiece = nbrPiece;
}
public void setNbrSalleBain(int nbrSalleBain) {
this.nbrSalleBain = nbrSalleBain;
}
public void setNbrWC(int nbrWC) {
this.nbrWC = nbrWC;
}
public void setCave(String cave) {
this.cave = cave;
}
public void setGarage(String garage) {
this.garage = garage;
}
public void setParking(String parking) {
this.parking = parking;
}
public void setBalcon(String balcon) {
this.balcon = balcon;
}
public void setSuperficieBalcon(float superficieBalcon) {
this.superficieBalcon = superficieBalcon;
}
} |
Voici la ou je définis ma TableView et je met des choses dans les colonnes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
@FXML
private TableView<Location> tableLocation;
@FXML
private TableColumn<Location, String> col_proLoc;
@FXML
private TableColumn<Location, String> col_locLoc;
// ObservableList Location
public static ObservableList<Location> oblistLocation = BddLocation.SelectLocation();
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
col_proLoc.setCellValueFactory(new PropertyValueFactory<>("Proprietaire"));
col_locLoc.setCellValueFactory(new PropertyValueFactory<>("Locataire"));
tableLocation.setItems(oblistLocation);
// La cellule du Proprio séléctionné
tableLocation.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> showLocationDetails(newValue));
} |
Puis comment j'appeles dans la BDD
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package fr.signoret.epreuve4.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import fr.signoret.epreuve4.model.Cste;
import fr.signoret.epreuve4.model.Locataire;
import fr.signoret.epreuve4.model.Location;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class BddLocation {
public static Connection getConnection() throws SQLException {
Connection connection = DriverManager.getConnection(Cste.url, Cste.login, Cste.password);
return connection;
}
static ObservableList<Location> oblistLocation = FXCollections.observableArrayList();
public static ObservableList<Location> SelectLocation() {
try {
Connection con = getConnection();
ResultSet result = con.createStatement().executeQuery("Select * FROM Location");
while(result.next()) {
oblistLocation.add(new Location(result.getInt(1), result.getInt(2),result.getInt(3),result.getFloat(4),result.getFloat(5),result.getString(6),result.getString(7),result.getInt(8),result.getString(9),result.getInt(10),result.getInt(11),result.getInt(12),result.getInt(13),result.getString(14),result.getString(15),result.getString(16),result.getString(17),result.getFloat(18)));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return oblistLocation;
}
} |
Je supposes qu'il doit y avoir quelques choses à faire avec les INNER JOIN ??
Merci à vous,