-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Donation Data Acsess Object created
- Loading branch information
AdrianBalunan
committed
Mar 13, 2026
1 parent
2f4abb0
commit 44206c0
Showing
1 changed file
with
32 additions
and
1 deletion.
There are no files selected for viewing
33 changes: 32 additions & 1 deletion
33
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/DAO/DonationDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,34 @@ | ||
| package ntnu.systemutvikling.team6.DAO; | ||
|
|
||
| public class DonationDAO {} | ||
| import ntnu.systemutvikling.team6.database.DatabaseConnection; | ||
| import ntnu.systemutvikling.team6.models.Charity; | ||
|
|
||
| import java.sql.*; | ||
| import java.util.Calendar; | ||
| import java.util.UUID; | ||
|
|
||
| public class DonationDAO { | ||
| private static final DatabaseConnection connection = new DatabaseConnection(); | ||
|
|
||
| public static void addDonation(Charity charity, double amount){ | ||
| String sql_query = | ||
| """ | ||
| INSERT INTO Donations (UUID_Donations, amount, date, Charities_UUID_charities) | ||
| VALUES (?, ?, ?, ?) | ||
| """; | ||
| try (Connection conn = connection.getMySqlConnection(); | ||
| PreparedStatement ps = conn.prepareStatement(sql_query)){ | ||
| conn.setAutoCommit(false); | ||
|
|
||
| ps.setString(1, UUID.randomUUID().toString()); | ||
| ps.setDouble(2, amount); | ||
| ps.setDate(3, new Date(System.currentTimeMillis())); | ||
| ps.setString(4, charity.getUUID().toString()); | ||
|
|
||
| ps.executeUpdate(); | ||
| conn.commit(); | ||
| } catch (SQLException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } |