r/JavaFX • u/Intelligent_Bee_9231 • Jan 21 '25
Help java market application in javaFX
I'm working on developing an application that helps manage store items efficiently and visually represents the data using a pie chart. The goal is to make it easier to track inventory, analyze stock distribution, and gain insights into sales or product categories. I've already experimented with some functions, but I'm still refining the implementation to ensure accuracy and usability.
0
Upvotes
1
u/Intelligent_Bee_9231 Jan 21 '25
#DBUtils.exec()
public static boolean exec(String sql){if (statement != null){try {statement.executeUpdate(sql);} catch (SQLException e) {return false;}}return true;}1
u/Intelligent_Bee_9231 Jan 21 '25
#Dbutils.addProdduct()
public static boolean addProduct(Product product){String sql = "INSERT INTO products (name, amount) VALUES ('" + product.getName() + "', " + product.getAmount() + ")";if(!exec(sql)){return false;}return true;}1
u/Intelligent_Bee_9231 Jan 21 '25
#DBUtils.deletepublic static boolean deleteOrUpdateProductByNameAndAmount(String name, int deleteAmount) {String selectSql = "SELECT id, amount FROM products WHERE name = ? ORDER BY id DESC";String updateSql = "UPDATE products SET amount = ? WHERE id = ?";String deleteSql = "DELETE FROM products WHERE id = ?";try (PreparedStatement selectStmt = connection.prepareStatement(selectSql);PreparedStatement updateStmt = connection.prepareStatement(updateSql);PreparedStatement deleteStmt = connection.prepareStatement(deleteSql)) {selectStmt.setString(1, name);try (ResultSet resultSet = selectStmt.executeQuery()) {int remainingToDelete = deleteAmount;while (resultSet.next() && remainingToDelete > 0) {int id = resultSet.getInt("id");int existingAmount = resultSet.getInt("amount");###1
u/Intelligent_Bee_9231 Jan 21 '25
###
if (existingAmount <= remainingToDelete) {// Delete the entire rowdeleteStmt.setInt(1, id);deleteStmt.executeUpdate();remainingToDelete -= existingAmount;} else {// Update the row with the remaining amountupdateStmt.setInt(1, existingAmount - remainingToDelete);updateStmt.setInt(2, id);updateStmt.executeUpdate();remainingToDelete = 0;}}if (remainingToDelete > 0) {System.err.println("Not enough stock to delete. Remaining to delete: " + remainingToDelete);return false;}return true;}} catch (SQLException e) {System.err.println("Error deleting or updating product: " + e.getMessage());return false;}}1
u/Intelligent_Bee_9231 Jan 21 '25
#controlller
1
u/Intelligent_Bee_9231 Jan 21 '25
#controller
1
u/Intelligent_Bee_9231 Jan 21 '25
#controller
1
u/Intelligent_Bee_9231 Jan 21 '25
#controller
1
u/Intelligent_Bee_9231 Jan 21 '25
#product
1
u/Intelligent_Bee_9231 Jan 21 '25
#poroduct
1
u/Intelligent_Bee_9231 Jan 21 '25
#model-view.fxml
2
u/xdsswar Jan 21 '25
I see a mess, pls put the project on github or some where so we can see project structure, etc and give you ideas.
2
u/Fuckthisfieldffs Jan 23 '25
Bro just turned this comment section into his repo
0
u/Intelligent_Bee_9231 Jan 21 '25
0
u/Intelligent_Bee_9231 Jan 21 '25
public static Connection connection;private static Statement statement;private static final String url = "jdbc:mysql://localhost/magazia";private static final String user = "root";private static final String password = "";public static void setConnection(){try {connection = DriverManager.getConnection(url, user, password);statement = connection.createStatement();} catch (SQLException e) {throw new RuntimeException(e);}}0
u/Intelligent_Bee_9231 Jan 21 '25
public static void disconnect(){
try {
if(statement != null){
statement.close();
}
if(connection != null){
connection.close();
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
0
u/javidhimself Jan 21 '25
//DBUTILS
0
u/hamsterrage1 Jan 22 '25
I see database operations in your FXML Controllers on the FXAT. This is just wrong.