Skip to content

Commit

Permalink
AccountDAO findAccountById method
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsundin committed Jan 30, 2024
1 parent cf4ec6f commit 96af2d0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/DAO/AccountDAO.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package DAO;

import Model.Account;

import Util.ConnectionUtil;

import java.sql.Connection;
Expand Down Expand Up @@ -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<Account> getAllAccounts() {
List<Account> accounts = new ArrayList<>();
try {
Expand Down

0 comments on commit 96af2d0

Please sign in to comment.