-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableView.java
More file actions
82 lines (70 loc) · 2.59 KB
/
TableView.java
File metadata and controls
82 lines (70 loc) · 2.59 KB
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
package kitordersystem;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.util.Callback;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author tsmoffat
*/
public class TableView{
private ObservableList<ObservableList> data;
private javafx.scene.control.TableView tableview;
public void buildData() throws SQLException, IOException {
Connection c;
data = FXCollections.observableArrayList();
try {
c = new getConnection().getConnection();
String SQL = "USE mydb";
ResultSet rs = c.createStatement().executeQuery(SQL);
// SQL FOR SELECTING TABLES
SQL = "select o.ID, o.CustomerID, c.Name, c.Email_Address, c.Squad, o.Order, o.OrderSize, o.OrderNumber, o.NameOnGarment, i.Item, o.PaidFor from Orders o INNER JOIN Customers c ON o.CustomerID = c.ID INNER JOIN Items i ON i.idItems=o.Order;";
// ResultSet
rs = c.createStatement().executeQuery(SQL);
/**
* Gets column headings and adds them to the TableView dynamically
*/
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
// We are using non property style for making dynamic table
final int j = i;
TableColumn col = new TableColumn(rs.getMetaData().getColumnName(i + 1));
col.setCellValueFactory(
new Callback<CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
tableview.getColumns().addAll(col);
}
/**
* Data added into the table and then set visible.
*/
while (rs.next()) {
// Iterate Row
ObservableList<String> row = FXCollections.observableArrayList();
for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) {
// Iterate Column
row.add(rs.getString(i));
}
System.out.println("Row [1] added " + row);
data.add(row);
}
tableview.setItems(data);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error on Building Data");
}
}
}