blob: 45aa84fbc72e55345ba2f7849f496a1eff2c3809 (
plain)
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
|
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import java.sql.*;
import javafx.collections.FXCollections;
public class SearchAction implements EventHandler<ActionEvent> {
private Text status;
private TextField field;
private PreparedStatement statement;
private ObservableList<Mark> marks = FXCollections.observableArrayList();
public SearchAction(Connection connection, Text status, TextField field) throws SQLException {
this.statement = connection.prepareStatement(
"SELECT english, german, math FROM marks WHERE name LIKE ?"
);
this.status = status;
this.field = field;
}
public void handle(ActionEvent action) {
try {
this.statement.setString(1, this.field.getText());
this.statement.execute();
var results = this.statement.getResultSet();
this.marks.clear();
if (results.next()) {
this.marks.add(new Mark("Englisch", results.getInt(1)));
this.marks.add(new Mark("Deutsch", results.getInt(2)));
this.marks.add(new Mark("Mathematik", results.getInt(3)));
}
} catch (Exception exception) {
this.status.setText(exception.getMessage());
}
}
public ObservableList<Mark> getMarks() {
return this.marks;
}
}
|