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
|
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import java.sql.*;
public class SaveAction implements EventHandler<ActionEvent> {
private TextField name;
private TextField english;
private TextField german;
private TextField math;
private Text status;
private PreparedStatement statement;
public SaveAction(
Connection connection,
TextField name,
TextField english,
TextField german,
TextField math,
Text status
) throws SQLException {
this.statement = connection.prepareStatement(
"INSERT INTO marks (name, english, german, math) VALUES (?, ?, ?, ?)"
);
this.name = name;
this.english = english;
this.german = german;
this.math = math;
this.status = status;
}
public void handle(ActionEvent event) {
try {
this.statement.setString(1, this.name.getText());
this.statement.setInt(2, Integer.parseInt(this.english.getText()));
this.statement.setInt(3, Integer.parseInt(this.german.getText()));
this.statement.setInt(4, Integer.parseInt(this.math.getText()));
this.statement.execute();
this.name.setText("");
this.english.setText("");
this.german.setText("");
this.math.setText("");
} catch (SQLException exception) {
this.status.setText(exception.getMessage());
}
}
}
|