From b61400fbbe1e94c5a4704cb756f6a926aec65cca Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 19 Feb 2026 06:05:59 +0000 Subject: [PATCH] Replace System.out.println with Logger in DatabaseHandler Replaced all instances of `System.out.println` and `e.printStackTrace()` in `src/library/assistant/database/DatabaseHandler.java` with Log4j 2 `LOGGER.log(...)` calls. This improves code health by ensuring consistent logging and allowing for better log management. Also fixed exception logging to ensure stack traces are preserved. Co-authored-by: G30RG3-GJ <203693057+G30RG3-GJ@users.noreply.github.com> --- .../assistant/database/DatabaseHandler.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/library/assistant/database/DatabaseHandler.java b/src/library/assistant/database/DatabaseHandler.java index e9c4f53..6dabb20 100644 --- a/src/library/assistant/database/DatabaseHandler.java +++ b/src/library/assistant/database/DatabaseHandler.java @@ -56,7 +56,7 @@ private static void inflateDB() { List tableData = new ArrayList<>(); try { Set loadedTables = getDBTables(); - System.out.println("Already loaded tables " + loadedTables); + LOGGER.log(Level.INFO, "Already loaded tables {}", loadedTables); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(DatabaseHandler.class.getClass().getResourceAsStream("/resources/database/tables.xml")); @@ -71,15 +71,15 @@ private static void inflateDB() { } } if (tableData.isEmpty()) { - System.out.println("Tables are already loaded"); + LOGGER.log(Level.INFO, "Tables are already loaded"); } else { - System.out.println("Inflating new tables."); + LOGGER.log(Level.INFO, "Inflating new tables."); createTables(tableData); } } catch (Exception ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } } @@ -115,7 +115,7 @@ public ResultSet execQuery(String query) { result = stmt.executeQuery(query); } catch (SQLException ex) { - System.out.println("Exception at execQuery:dataHandler" + ex.getLocalizedMessage()); + LOGGER.log(Level.ERROR, "Exception at execQuery:dataHandler", ex); return null; } finally { @@ -131,7 +131,7 @@ public boolean execAction(String qu) { } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Error:" + ex.getMessage(), "Error Occured", JOptionPane.ERROR_MESSAGE); - System.out.println("Exception at execQuery:dataHandler" + ex.getLocalizedMessage()); + LOGGER.log(Level.ERROR, "Exception at execQuery:dataHandler", ex); return false; } finally { @@ -149,7 +149,7 @@ public boolean deleteBook(Book book) { } } catch (SQLException ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } return false; } @@ -162,12 +162,12 @@ public boolean isBookAlreadyIssued(Book book) { ResultSet rs = stmt.executeQuery(); if (rs.next()) { int count = rs.getInt(1); - System.out.println(count); + LOGGER.log(Level.INFO, "Book issue count: {}", count); return (count > 0); } } catch (SQLException ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } return false; } @@ -183,7 +183,7 @@ public boolean deleteMember(MemberListController.Member member) { } } catch (SQLException ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } return false; } @@ -196,12 +196,12 @@ public boolean isMemberHasAnyBooks(MemberListController.Member member) { ResultSet rs = stmt.executeQuery(); if (rs.next()) { int count = rs.getInt(1); - System.out.println(count); + LOGGER.log(Level.INFO, "Member issue count: {}", count); return (count > 0); } } catch (SQLException ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } return false; } @@ -218,7 +218,7 @@ public boolean updateBook(Book book) { return (res > 0); } catch (SQLException ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } return false; } @@ -235,7 +235,7 @@ public boolean updateMember(MemberListController.Member member) { return (res > 0); } catch (SQLException ex) { - LOGGER.log(Level.ERROR, "{}", ex); + LOGGER.log(Level.ERROR, "Exception occurred", ex); } return false; } @@ -261,7 +261,7 @@ public ObservableList getBookGraphStatistics() { } } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.ERROR, "Exception occurred", e); } return data; } @@ -283,7 +283,7 @@ public ObservableList getMemberGraphStatistics() { } } catch (Exception e) { - e.printStackTrace(); + LOGGER.log(Level.ERROR, "Exception occurred", e); } return data; } @@ -292,7 +292,7 @@ private static void createTables(List tableData) throws SQLException { Statement statement = conn.createStatement(); statement.closeOnCompletion(); for (String command : tableData) { - System.out.println(command); + LOGGER.log(Level.INFO, "Executing SQL command: {}", command); statement.addBatch(command); } statement.executeBatch();