Java

Point of Sales System Using Java and Mysql

The Point of  sales System is developed using Java and mysql. The project is built to manage  items and transactions. To make a new transaction, fields such as: item code, name, qty and payment needs to be selected. If you like to learn point of sales systems step by step, this is the right place to learn from the beginning.

Lets is see How to do the Project Step by Step

First Step Establish the Database Connection

import the Sql NameSpace above of the programming :  import java.sql.*;

    Connection con;
    PreparedStatement pst;
    ResultSet rs;
    DefaultTableModel model = new DefaultTableModel();
    
    
    public void Connect()
    {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
             con = DriverManager.getConnection("jdbc:mysql://localhost/pos","root","");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Sales.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(Sales.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }

Paste this Code inside the keypress Event of the textbox. we created the textbox name txtCode of this project.

if you enter the item code of the text filed the code matching item details would be displayed.

 if(evt.getKeyCode() == KeyEvent.VK_ENTER)
        {
          String itemCode = txtCode.getText();
        try {
             pst = con.prepareStatement("select * from product where itemcode=?");
             pst.setString(1, itemCode);
             rs = pst.executeQuery();
                    
                    if(rs.next()==true)
                    {
                        String productname = rs.getString("pname");
                        String price = rs.getString("price");
   
                        txtpname.setText(productname.trim());
                        txtPrice.setText(price.trim());
                        
                    }
                    else
                    {
                       JOptionPane.showMessageDialog(this,"Barcode not Found");
                        
                    }
        } catch (SQLException ex) {
            Logger.getLogger(Sales.class.getName()).log(Level.SEVERE, null, ex);
        }

       }

Add the Product details into the JTable

After receiving the product name and price where the user has the option to add the qty by clicking the add button to see all Products details which will be shown in the above table.

  int price = Integer.parseInt(txtPrice.getText());
  int qty = Integer.parseInt(txtQty.getText());
        
  int tot = price * qty;
        
        
  model = (DefaultTableModel)jTable1.getModel();
  model.addRow(new Object[]
    {
      txtCode.getText(),
      txtpname.getText(),
      txtQty.getText(),
      txtPrice.getText(),
      tot
                         
    });    
                     
                     
     int sum=0;
     int items = jTable1.getRowCount();
     for(int i=0; i<jTable1.getRowCount(); i++)
       {            
         sum = sum + Integer.parseInt(jTable1.getValueAt(i, 4).toString());
                         
       }
                        
         txtSub.setText(Integer.toString(sum));
         lblSubtoal.setText(Integer.toString(sum));  
         lblItems.setText(Integer.toString(items));

         txtCode.setText("");
         txtpname.setText("");
         txtQty.setText(""); 
         txtPrice.setText("");
         txtCode.requestFocus();

After Calculate the Subtotal you have to pay the payment after enter the payment balance would be calculate and displayed on the balance textbox.

 int subtot = Integer.parseInt(txtSub.getText());
 int pay = Integer.parseInt(txtPay.getText());
        
 int tot = pay - subtot;
        
 txtBal.setText(String.valueOf(tot));

After the done the Sales Transaction Click the Button Finish then Clear up your all Form Windows.

   model.setRowCount(0);
       
   lblItems.setText("");
        
   txtSub.setText("");
        
   txtPay.setText("");
         
   txtBal.setText("");
          
   txtCode.requestFocus();
   lblSubtoal.setText("");

i have attached the video link below. which will do this tutorials step by step.

 

 

admin

Recent Posts

GitHub Copilot vs Microsoft Copilot Best AI Tool to Use in 2025

GitHub is a powerful tool used by teams and developers around the globe. This guide is…

3 days ago

Chat with Claude AI Free – Your Super-Smart AI Buddy

It's like having a super-smart buddy that is always there to help you write stories,…

7 days ago

Best Festivals UK 2025 [Free Guide Included]

The UK is known for its rich history, diverse culture, and most of all  its…

1 week ago

Bank Holidays 2025 UK – Plan Your Perfect Long Weekends

Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…

1 week ago

Master Cursor AI Full Guide for Students & Creators

The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…

2 weeks ago

Google Gemini AI Free AI Tool for Students & Creators

Google Gemini AI is among the top talked about developments. What exactly is it? What…

2 weeks ago