-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller_insertstock.java
84 lines (70 loc) · 3.21 KB
/
controller_insertstock.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class controller_insertstock {
public TableView<motorcycle> viewTable;
public TableColumn<motorcycle, String> idColumn;
public TableColumn<motorcycle, String> brandColumn;
public TableColumn<motorcycle, String> productColumn;
public TableColumn<motorcycle, String> colourColumn;
public TextField brand,product,colour,name;
ObservableList<motorcycle> history = FXCollections.observableArrayList();
public void back() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("ADMIN MENU.fxml"));
Parent root = loader.load();
Main.primaryStage.setScene(new Scene(root));
}
public void finish() throws IOException {
String sql = String.format("insert into motorcycle(Brand,Product,Colour) VALUES('%s', '%s' ,'%s')" ,brand.getText(),product.getText(),colour.getText());
System.out.println(sql);
try {
Connection conn = Main.connect.con;
// create the java statement
Statement st = conn.createStatement();
st.executeUpdate(sql);
System.out.println("Data Inserted");
}
catch (Exception e){
System.out.println(e);
}
FXMLLoader loader = new FXMLLoader(getClass().getResource("INSERTSTOCKSUKSES.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)); // add new motorcycle data
}
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);
}
}