-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller_checkstockuser.java
65 lines (54 loc) · 2.47 KB
/
controller_checkstockuser.java
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
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLOutput;
import java.sql.Statement;
public class controller_checkstockuser {
//configure the table
public TableView<motorcycle> viewTable;
public TableColumn<motorcycle, String> idColumn; // call all the table from the database to show up
public TableColumn<motorcycle, String> brandColumn;
public TableColumn<motorcycle, String> productColumn;
public TableColumn<motorcycle, String> colourColumn;
ObservableList<motorcycle> history = FXCollections.observableArrayList();
public void back() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("USER MENU.fxml"));
Parent root = loader.load();
Main.primaryStage.setScene(new Scene(root));
}
public void initialize() throws Exception {
String query = "SELECT * FROM motorcycle";
Connection conn = Main.connect.con;
// create the java statement
Statement st = conn.createStatement();
// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);
// iterate through the java resultset
while (rs.next()) {
String ID = rs.getString("ID");
String Brand = rs.getString("Brand");
String Product = rs.getString("Product");
String Colour = rs.getString("Colour");
System.out.println(ID);
System.out.println(Brand);
System.out.println(Product);
System.out.println(Colour);
history.add(new motorcycle(ID,Brand, Product, Colour));
}
// giving fx:id
idColumn.setCellValueFactory(new PropertyValueFactory<motorcycle, String>("ID"));
brandColumn.setCellValueFactory(new PropertyValueFactory<motorcycle, String>("Brand"));
productColumn.setCellValueFactory(new PropertyValueFactory<motorcycle, String>("Product"));
colourColumn.setCellValueFactory(new PropertyValueFactory<motorcycle, String>("Colour"));
// load dummy data
viewTable.setItems(history);
}
}