add a model to manage data

This commit is contained in:
2025-10-02 10:47:14 +02:00
parent e35f36db4b
commit 8b6d447574
3 changed files with 12 additions and 6 deletions

View File

@@ -28,10 +28,13 @@ public class Database {
public Votes getVotesFromCompetitor(String country) {
try {
PreparedStatement query = this.connection.prepareStatement(
"SELECT Countries.name Votes.points" +
"FROM Votes JOIN Countries ON Votes.competitor_id = Countries.id" +
"WHERE Countries.name = " + country
"SELECT Voters.name, Votes.points " +
"FROM Votes " +
"JOIN Countries AS Competitors ON Votes.competitor_id = Competitors.id " +
"JOIN Countries AS Voters ON Votes.voter_id = Voters.id " +
"WHERE Competitors.name = ?;"
);
query.setString(1, country);
ResultSet result = query.executeQuery();
ArrayList<Vote> voteList = new ArrayList<>();
@@ -48,7 +51,7 @@ public class Database {
return new Votes(country, voteList);
} catch(SQLException exception) {
System.err.println("Error while trying to prepare or execute the query.");
System.err.println("Error while trying to prepare or execute the query (" + exception.getMessage() + ").");
}
return null;