Funktion fürs einfügen in die DB
This commit is contained in:
		@@ -10,6 +10,7 @@ import javafx.scene.layout.*;
 | 
				
			|||||||
import javafx.scene.text.TextAlignment;
 | 
					import javafx.scene.text.TextAlignment;
 | 
				
			||||||
import javafx.stage.Stage;
 | 
					import javafx.stage.Stage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.sql.PreparedStatement;
 | 
				
			||||||
import java.sql.ResultSet;
 | 
					import java.sql.ResultSet;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class HappyBirdMain extends Application {
 | 
					public class HappyBirdMain extends Application {
 | 
				
			||||||
@@ -829,4 +830,27 @@ public class HappyBirdMain extends Application {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        return bestFiveHighscores;
 | 
					        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");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user