From 96af2d0fb79350bfe0c70abcbc7ac9cfa47b7017 Mon Sep 17 00:00:00 2001 From: Jon Sundin Date: Tue, 30 Jan 2024 00:40:56 +0000 Subject: [PATCH] AccountDAO findAccountById method --- src/main/java/DAO/AccountDAO.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/DAO/AccountDAO.java b/src/main/java/DAO/AccountDAO.java index f0112af..cf05f27 100644 --- a/src/main/java/DAO/AccountDAO.java +++ b/src/main/java/DAO/AccountDAO.java @@ -1,7 +1,6 @@ package DAO; import Model.Account; - import Util.ConnectionUtil; import java.sql.Connection; @@ -60,6 +59,26 @@ public Account findAccountByUsername(String username) { return null; } + public Account findAccountByAccountId(int account_id) { + try { + Connection conn = ConnectionUtil.getConnection(); + String sql = "SELECT username FROM account WHERE account_id = ?;"; + PreparedStatement ps = conn.prepareStatement(sql); + ps.setInt(1, account_id); + ResultSet rs = ps.executeQuery(); + while (rs.next()) { + Account account = new Account(); + String username = rs.getString(1); + account.setUsername(username); + account.setAccount_id(account_id); + return account; + } + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + public List getAllAccounts() { List accounts = new ArrayList<>(); try {