diff --git a/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java index 29891cd..9fecd85 100644 --- a/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java +++ b/Happy_Bird/src/main/java/com/example/happy_bird/HappyBirdMain.java @@ -10,6 +10,7 @@ import javafx.scene.layout.*; import javafx.scene.text.TextAlignment; import javafx.stage.Stage; +import java.sql.PreparedStatement; import java.sql.ResultSet; public class HappyBirdMain extends Application { @@ -829,4 +830,27 @@ public class HappyBirdMain extends Application { } return bestFiveHighscores; } + + /*** + * Fügt die erreichte Punktzahl des Spielers für den Spieler mit seinem Namen und Kürzel in die Datenbank ein + * @param points die erreichten Punkte + */ + public void writeIntoDatabase(int points) + { + String playername = nameLabel.getText(); + String playeracronym = acronymLabel.getText(); + /*String sql = "INSERT INTO happybirddb(name, kuerzel, punkte) VALUES ('" + playername + "', '" + points + + "', '" + playeracronym + "');";*/ + String sql = "INSERT INTO happybirddb (name, kuerzel, punkte) VALUES (?, ?, ?);"; + try (PreparedStatement ps = datenbank.con.prepareStatement(sql)) { + ps.setString(2, playername); + ps.setInt(3, points); + ps.setString(4, playeracronym); + ps.execute(); + } + catch (Exception e) + { + System.out.println("Insert fehlschlagen"); + } + } } \ No newline at end of file