Make an Inventory Management System Step by Step Using Java, Eclipse, AWT/Swing, Window Builder and MySQL Database


  • 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.


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();
	}
		
}

public void loadTable() {
		
	try {
		prestm = con.prepareStatement("select * from InventoryTable");
		
		rst = prestm.executeQuery();
		
		table.setModel(DbUtils.resultSetToTableModel(rst));
		
		
	} catch (SQLException e) {
		e.printStackTrace();
	}
		
}


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);


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);


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);

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);

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);

JButton btnExit = new JButton("Exit");
btnExit.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
		
		System.exit(0);
		
	}
});

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);

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);

28 Comments.

  1. 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!

  2. 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!

  3. 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!

  4. 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.

  5. 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.

  6. 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.

Leave a Reply to roupa intima feminina de renda Cancel reply

Your email address will not be published. Required fields are marked *