JAVA Inventory System Source Code

Inventory Management System Source Code Using JAVA NetBeans And MySQL Database

Java inventory management system project

In this Java project demo, we will demonstrate how to use our inventory management system developed with Java NetBeans and MySQL database.

Goals of this project:
- To provide students and curious individuals with an example they can learn from.
- To help people create their first project. 
- To share knowledge with others.

Tools:
- Java programming language.
- netbeans IDE 8.2.
- MySQL database.
- Canva.com for images.
- Flatuicolorpicker.com for colors.
- Text file to generate order.

Watch This Full Project Demo


Watch The Project Setup Tutorial



1 - Login Form

The login form allows both the administrator and other users to log in to the home form of the application.

java inventory system - login form

If the user enters the wrong username or password, a message will show up.

java inventory system - login form error

If everything is okay, clicking the login button will display the main/home form and close the login form.


2 - Home Form

if the user type is ADMIN a "User" tab will be visible on the top menu

java inventory system - admin home form


if the user type is USER the "User" tab will be invisible

java inventory system - user home form


3 - Product Section


when you click on the Product tab, the MANAGE_PRODUCTS_FORM will show up



java inventory system - manage products



- on the form load all products will be displayed into a jtable.

- when you enter a value in the search box and click search button, only the products that contain this value will be shown in the jtable.



java inventory system - search products



When you click on the 'Add New Product' button, the Add_Product_Form will appear, which allows you to enter the new product data and insert it into the MySQL database.


java inventory system - add new product

In the top form, you can see a combobox labeled 'categories'. The options in this combobox are populated from the 'category' table in the MySQL database, using a HashMap to map the category names to their respective IDs.

and if you want to update a product just select the product you want to edit from the jtable and click on the "Edit Selected Product" and the Edit_Product_Form will show up with all the selected product data displayed on the form. 

java inventory system - edit selected product

when you want to delete a product just select the product you want to remove and click on the "Remove Selected Product" button.


NOTE: when you Edit or Remove a product click on the "Refresh" button to see the updated results in the jtable..


4 - Category Section


now if you want to manage the categories you have to go to the category tab.
- when you click on the category tab the MANAGE_CATEGORIES_FORM will show up.

- you can insert a new category by just entering the name on the textfield and click the "Insert New Category" button.

- The MANAGE_CATEGORIES_FORM includes a jtable listing all categories by name and ID.

- if you select a category from the jtable : 1) the data of the selected category will be displayed on the textfields, 2) the products on the selected category will be displayed on a list. 

- also navigation buttons for next and previous .



java inventory system - manage categories



- when you click on "show full  products list in this category" button a a list ( in a form ) of all products in this category will be displayed"..



java inventory system - show products in a category



5 - Customer Section


in this section you can:

- see all the customers in database displayed on jtable.

- get the selected customer data from jtable and set it into jtextfields on jtable click.

- insert a new customer.

- update the selected customer data.

- delete the selected customer.

- navigate using "Next" & "Previous".

- clear all jtextfields text using the "clear" buttons.

- display the selected customer orders count.

- display the selected customer total orders amount.

- display the selected customer last order date.



java inventory system - manage customers



6 - Order Section


When you click on the 'Order' tab, the 'MANAGE_ORDERS_FORM' will show up, which contains:

- 1 'jTable' with all customers.

- 1 'jTable' for products (showing products depending on the selected category in the combobox).

- 1 'jTable' to display the products you want to add to the order .



java inventory system - manage orders



Watch A Full Order Section Demonstration


on the jtable for customers, if you select a row the customer id will be set into the jtextfield id.



Now, if you want to add products to the order, follow these steps:

1 - Select the category you want from the combobox.

2 - Click on the product you want to add, then click on the '>>>' button. Enter the quantity you want. Note that you cannot enter 0 or leave the box empty, and you cannot enter a quantity higher than what is available in the database.





java inventory system - quantity



java inventory system - quantity 0



java inventory system - unavailable quantity





If everything is okay, the selected product will be added to the order JTable with the quantity you want.








now lets add more products to the order table



java inventory system - add products to order




- in the jtable you can see a column "Quantity X Price" where we calculate the total price for this product.
- on the bottom you can see the total amount of all products.


java inventory system - order buttons



- The "Remove Product" button allows you to remove the selected product from the order table.
- The "Clear" button allows you to remove all products from the order table.



if all is good, click the "Insert Order" button to add the new order with the details into the database.



If you want to view all the orders, click on the 'Show All Orders' button, and the All_Orders_Form will appear with all the orders displayed in a jTable.



java inventory system - show all orders





when you click on "Print Selected Order" the selected order will be printed into a text file.




java inventory system - print order


7 - User Section

The last tab is for users, which is only accessible by the admin. When the user tab is clicked, the MANAGE_USERS_FORM will appear, displaying all users in a jtable.

- When you select a user from the JTable, all of their data will be populated into text fields, allowing you to edit or delete the information.

- And to add a new user, enter the user information and click on the 'Insert' button.
java inventory system - manage users

Java - Login And Register Form With MySQL DataBase

How To Make SignUp And SignIn Form In Java Using NetBeans With MySQL DataBase

Java - Login And Register Form With MySQL DataBase


in a previous Java tutorial we did a login and register form design ( video link: https://youtu.be/XAowXcmQ-kA ), 
and in this one will see how to connect the login and signup form with a mysql database

to do that you need to download mysql connector, watch tutorial from here: https://www.youtube.com/watch?v=zM7oe2_S-jY
and add it to your project

we will ceate a class (MyConnection) to connect our login and register forms with mysql database

in the register form wi will create a function (checkUsername) to check if the username you want to register is already exists in the database table

what we will check when the user click on the register button:
- if the username jtextfield is empty
- if the password jtextfield is empty
- if the retype_password text is equal to the password text
- if the username already exists in the database using the "checkUsername" function
- if the jdatechooser is empty

in the login fom it's simple;
the user enter his login and password and click on the login button,

and all we have to do is to check if a user with this username and password already exists on the database, and if the user don't exists show a warning message , else show a new form with the user username displayed on a jlabel.






Project Source Code:


------------ Create A Class "MyConnection" To Connect Our Forms With Database

import java.sql.Connection;
import java.sql.DriverManager;


/**
 *
 * @author 1BestCsharp
 */
public class MyConnection {
    
    
    // create a function to connect with mysql database
    
    public static Connection getConnection(){
     
        Connection con = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/java_login_register", "root", "");
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
        
        return con;
    }
    
}    



------------ On The Register Form ------------

// function to check if the username already exist in database table
    public boolean checkUsername(String username)
    {
        PreparedStatement ps;
        ResultSet rs;
        boolean checkUser = false;
        String query = "SELECT * FROM `the_app_users` WHERE `u_uname` =?";
        
        try {
            ps = MyConnection.getConnection().prepareStatement(query);
            ps.setString(1, username);
            
            rs = ps.executeQuery();
            
            if(rs.next())
            {
                checkUser = true;
            }
        } catch (SQLException ex) {
            Logger.getLogger(RegisterForm.class.getName()).log(Level.SEVERE, null, ex);
        }
         return checkUser;
    }




// on the register button click
private void jButton_Register_ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        String fname = jTextField_FN.getText();
        String lname = jTextField_LN.getText();
        String uname = jTextField_UN.getText();
        String pass = String.valueOf(jPasswordField_PASS.getPassword());
        String re_pass = String.valueOf(jPasswordField_REPASS.getPassword());
        String bdate = null;
        String address = jTextArea_ADDRESS.getText();
                
        if(uname.equals(""))
        {
            JOptionPane.showMessageDialog(null, "Add A Username");
        }
        
        else if(pass.equals(""))
        {
            JOptionPane.showMessageDialog(null, "Add A Password");
        }
        else if(!pass.equals(re_pass))
        {
            JOptionPane.showMessageDialog(null, "Retype The Password Again");
        }
        
        else if(checkUsername(uname))
        {
            JOptionPane.showMessageDialog(null, "This Username Already Exist");
        }
        
        else{
        
        if(jDateChooser_BDATE.getDate() != null)
        {
            SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
            bdate = dateformat.format(jDateChooser_BDATE.getDate());
        }
            
        PreparedStatement ps;
        String query = "INSERT INTO `the_app_users`(`u_fname`, `u_lname`, `u_uname`, `u_pass`, `u_bdate`, `u_address`) VALUES (?,?,?,?,?,?)";
        
        try {
            ps = MyConnection.getConnection().prepareStatement(query);
            
            ps.setString(1, fname);
            ps.setString(2, lname);
            ps.setString(3, uname);
            ps.setString(4, pass);
            
            if(bdate != null)
            {
             ps.setString(5, bdate);
            }else{
                ps.setNull(5, 0);
            }
            ps.setString(6, address);
            
            if(ps.executeUpdate() > 0)
            {
                JOptionPane.showMessageDialog(null, "New User Add");
            }
            
        } catch (SQLException ex) {
            Logger.getLogger(RegisterForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }                                                 

    

------------ On The Login Form ------------


// on the login button click
private void jButton_LOGINActionPerformed(java.awt.event.ActionEvent evt) {                                 
        PreparedStatement ps;
        ResultSet rs;
        String uname = jTextField1.getText();
        String pass = String.valueOf(jPasswordField1.getPassword());
        
        String query = "SELECT * FROM `the_app_users` WHERE `u_uname` =? AND `u_pass` =?";
        
        try {
            ps = MyConnection.getConnection().prepareStatement(query);
            
            ps.setString(1, uname);
            ps.setString(2, pass);
            
            rs = ps.executeQuery();
            
            if(rs.next())
            {
                    HOME_JFrame mf = new HOME_JFrame();
                    mf.setVisible(true);
                    mf.pack();
                    mf.setLocationRelativeTo(null);
                    mf.setExtendedState(JFrame.MAXIMIZED_BOTH);
                    mf.jLabel1.setText("Welcome < "+uname+" >");
                    
                    this.dispose();
            }
            else{
                    JOptionPane.showMessageDialog(null, "Incorrect Username Or Password", "Login Failed", 2);
                }
            
        } catch (SQLException ex) {
            Logger.getLogger(LoginForm.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
    }                                             


////// OUTPUT : 


java register form - add username
java register form - add username
it's the same for password and retype password

java register form - username already exists
java register form - username already exists
java login form - login failed
java login form - login failed
java login form - login success
java login form - login success -> show new form



download the source code





More Java Projects: