Here is a demonstration of the project that this post will discuss.

1. Features of the Project:
- Add Item: Allows adding a new item to the inventory
- Clear Form: Clears all fields or resets the form to its default state.
- Search Item: Enables searching for specific items within the inventory.
- Update Item: Allows updating the details or quantities of existing items.
- Delete Item: Removes an item from the inventory.
- Show Inventory: Displays the current list of items in the inventory.
- Sell Items: Facilitates the process of selling items from the inventory.
2. Watch this Complete One Shot Video Tutorial to build this project [This tutorial will provide excellent assistance]

3. Build Connection Code
public void buildConnection() {
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/SwingProjectDatabase", "root", "root@123");
System.out.println("Done with the stable conncetion");
} catch (SQLException e) {
e.printStackTrace();
}
}
4. Load Table Code
public void loadTable() {
try {
prestm = con.prepareStatement("select * from InventoryTable");
rst = prestm.executeQuery();
table.setModel(DbUtils.resultSetToTableModel(rst));
} catch (SQLException e) {
e.printStackTrace();
}
}
5. Add Item in the Inventory Code
JButton btnAddItem = new JButton("Add Item");
btnAddItem.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
btnAddItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name,quantity, price;
name = txtPname.getText();
quantity = txtQuantity.getText();
price = txtPrice.getText();
try {
prestm = con.prepareStatement("insert into InventoryTable(ProductName, Quantity, PricePerItem)values(?,?,?)");
prestm.setString(1, name);
prestm.setString(2, quantity);
prestm.setString(3, price);
prestm.executeUpdate();
JOptionPane.showMessageDialog(null,"Item Added!!");
loadTable();
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
btnAddItem.setBounds(18, 202, 123, 40);
panel.add(btnAddItem);
6. Clear Data Code
JButton btnClear = new JButton("Clear");
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
}
});
btnClear.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
btnClear.setBounds(146, 202, 123, 40);
panel.add(btnClear);
7. Search Item in the inventory Code
JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String searchId = txtSearchId.getText();
try {
prestm = con.prepareStatement("select * from InventoryTable where ID=?");
prestm.setString(1, searchId);
rst = prestm.executeQuery();
if(rst.next()) {
txtPname.setText(rst.getString(2));
txtQuantity.setText(rst.getString(3));
txtPrice.setText(rst.getString(4));
}else {
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
btnSearch.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
btnSearch.setBounds(72, 71, 123, 40);
panel_1.add(btnSearch);
8. Update Inventory Item Code
JButton btnUpdate = new JButton("Update");
btnUpdate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name,quantity, price, id;
name = txtPname.getText();
quantity = txtQuantity.getText();
price = txtPrice.getText();
id = txtSearchId.getText();
try {
prestm = con.prepareStatement("update InventoryTable set ProductName=?, Quantity=?, PricePerItem=? where ID=?");
prestm.setString(1, name);
prestm.setString(2, quantity);
prestm.setString(3, price);
prestm.setString(4, id);
prestm.executeUpdate();
JOptionPane.showMessageDialog(null,"Item Updated!!");
loadTable();
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
btnUpdate.setBounds(19, 23, 96, 40);
btnUpdate.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
panel_2.add(btnUpdate);
9. Delete Inventory Item Code
JButton btnDelete = new JButton("Delete");
btnDelete.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = txtSearchId.getText();
try {
prestm = con.prepareStatement("delete from InventoryTable where ID=?");
prestm.setString(1, id);
prestm.executeUpdate();
JOptionPane.showMessageDialog(null,"Item Deleted!!");
loadTable();
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
btnDelete.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
btnDelete.setBounds(144, 24, 105, 39);
panel_2.add(btnDelete);
10. Exit the Application Code
JButton btnExit = new JButton("Exit");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
11. Sell Item from the Inventory Code
JButton btnSellItem = new JButton("Sell Item");
btnSellItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name,quantity, price, id;
name = txtPname.getText();
quantity = txtQuantity.getText();
price = txtPrice.getText();
id = txtSellId.getText();
String sellQuantity = txtSellQuantity.getText();
Integer diffQuantity = Integer.parseInt(quantity) - Integer.parseInt(sellQuantity);
try {
prestm = con.prepareStatement("update InventoryTable set Quantity=? where ID=?");
prestm.setString(1, diffQuantity.toString());
prestm.setString(2, id);
prestm.executeUpdate();
JOptionPane.showMessageDialog(null,"Items Sold!!");
loadTable();
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
btnSellItem.setFont(new Font("Lucida Grande", Font.PLAIN, 16));
btnSellItem.setBounds(132, 142, 123, 40);
panel_4.add(btnSellItem);
12. Quantity Available in the Inventory Code
txtSellQuantity = new JTextField();
txtSellQuantity.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
String sellId = txtSellId.getText();
String sellQuantity = txtSellQuantity.getText();
try {
prestm = con.prepareStatement("select * from InventoryTable where ID=?");
prestm.setString(1, sellId);
rst = prestm.executeQuery();
if(rst.next()) {
if(Integer.parseInt(sellQuantity)<=Integer.parseInt(rst.getString(3))) {
txtPname.setText(rst.getString(2));
txtQuantity.setText(rst.getString(3));
txtPrice.setText(rst.getString(4));
}else {
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
}
}else {
txtPname.setText("");
txtQuantity.setText("");
txtPrice.setText("");
txtPname.requestFocus();
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
txtSellQuantity.setColumns(10);
txtSellQuantity.setBorder(new LineBorder(new Color(0, 0, 0)));
txtSellQuantity.setBounds(199, 87, 102, 26);
panel_4.add(txtSellQuantity);
Your ability to distill complex concepts into digestible nuggets of wisdom is truly remarkable. I always come away from your blog feeling enlightened and inspired. Keep up the phenomenal work!
Thank you so much for your valuable feedback and kind words.
مرحبًا، أعتقد أن هذه مدونة ممتازة. لقد عثرت عليها بالصدفة ;
pokračovat v tom, abyste vedli ostatní.|Byl jsem velmi šťastný, že jsem objevil tuto webovou stránku. Musím vám poděkovat za váš čas
fortsæt med at guide andre. Jeg var meget glad for at afdække dette websted. Jeg er nødt til at takke dig for din tid
Díky moc!|Hej, jeg synes, dette er en fremragende blog. Jeg snublede over det;
My developer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am anxious about switching to another platform. I have heard very good things about blogengine.net. Is there a way I can import all my wordpress posts into it? Any kind of help would be greatly appreciated!
Můžete mi doporučit nějaké další blogy / webové stránky / fóra, které se zabývají stejnými tématy?
Hello there, just became aware of your blog through Google, and found that it is really informative. I am gonna watch out for brussels. I will be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers!
på grund af denne vidunderlige læsning !!! Jeg kunne bestemt virkelig godt lide hver eneste lille smule af det, og jeg
I was very happy to uncover this web site. I need to to thank you for your time due to this wonderful read!! I definitely really liked every little bit of it and i also have you book-marked to look at new things on your blog.
It’s a shame you don’t have a donate button! I’d definitely donate to this fantastic blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will share this site with my Facebook group. Chat soon!
Hey there! Someone in my Myspace group shared this site with us so I came to take a look. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers! Terrific blog and terrific design.
reading this weblog’s post to be updated daily.
I will revisit once again since i have book-marked it. Money and freedom is the best way to change, may you be rich and continue to guide others.
I truly love your website.. Excellent colors & theme. Did you develop this website yourself? Please reply back as I’m attempting to create my very own site and would like to know where you got this from or what the theme is called. Appreciate it.
Introducing to you the most prestigious online entertainment address today. Visit now to experience now!
Introducing to you the most prestigious online entertainment address today. Visit now to experience now!
Greetings! Very helpful advice in this particular article! It is the little changes that will make the greatest changes. Thanks a lot for sharing!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I do not even know how I ended up here, but I thought this post was good. I do not know who you are but definitely you’re going to a famous blogger if you are not already Cheers!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
This website was… how do I say it? Relevant!! Finally I have found something which helped me. Thank you!
There’s a poetic stillness in your prose that invites deeper contemplation and leaves a lasting impression.
Thanks for your kind feedback! So nice of you!
Reading your piece felt like walking through a lush garden of ideas, each one blooming with vibrant insights that invited both contemplation and joy. Your words move with such effortless grace, and the way you bring together seemingly disparate thoughts into a cohesive whole is nothing short of magical. It’s a rare gift to make complex ideas feel so accessible, yet so profound.
Thanks for your kind feedback! So nice of you!