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
| package application;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class GUIConsulter
{
TableView<InfoVehicule> table;
Statement statement = null;
public GUIConsulter(BorderPane root, Stage primaryStage) throws SQLException
{
TableColumn<InfoVehicule, String> colonneMarque = new TableColumn<>("Marque");
colonneMarque.setCellValueFactory(new PropertyValueFactory<>("marque"));
TableColumn<InfoVehicule, String> colonneModele = new TableColumn<>("Modèle");
colonneModele.setCellValueFactory(new PropertyValueFactory<>("modele"));
TableColumn<InfoVehicule, String> colonneImmatriculation = new TableColumn<>("Immatriculation");
colonneImmatriculation.setCellValueFactory(new PropertyValueFactory<>("immatriculation"));
TableColumn colonneBoutonDetails = new TableColumn("");
colonneBoutonDetails.setCellValueFactory(new PropertyValueFactory<InfoVehicule, String>("boutonDetails"));
table = new TableView<>();
table.setItems(getVehicule());
table.getColumns().addAll(colonneMarque, colonneModele, colonneImmatriculation, colonneBoutonDetails);
root.setCenter(table);
}
public ObservableList<InfoVehicule> getVehicule() throws SQLException
{
table.setTranslateY(10);
ObservableList<InfoVehicule> vehicules = FXCollections.observableArrayList();
ConnectionBddSQLite connection = new ConnectionBddSQLite("bddVehicules.db");
Connection conn = connection.connect();
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM vehicules");
while (rs.next())
{
vehicules.add(new InfoVehicule(rs.getString("marque").toUpperCase(), rs.getString("modele").toUpperCase(),
rs.getString("immatriculation").toUpperCase().toUpperCase(),
"Détails " + rs.getString("immatriculation").toUpperCase()));
System.err.println("Marque : " + rs.getString("marque"));
System.err.println("Modele : " + rs.getString("modele"));
System.err.println("Immatriculation : " + rs.getString("immatriculation"));
System.err.println("**************************************************************");
}
connection.disconnect();
conn.close();
return vehicules;
}
} |
Partager