Java

Customer Count using Java Mysql

This tutorial will teach you how to create customer count using java mysql.this program help you find no of customers.

  • The user shall be able to register the customer.
  • The user shall be able to count the no of customer.

Establish the Database Connection

public void Connect()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/gsm", "root", "");
            
            
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
        
    }

Add Records

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        String name = txtname.getText();
        String address = txtaddress.getText();
        String phone = txtphone.getText();  
        
        try {
            pst = con.prepareStatement("insert into customer(name,address,phone)values(?,?,?)");
            pst.setString(1, name);
            pst.setString(2, address);
            pst.setString(3, phone);
            int k = pst.executeUpdate();
            
            if(k==1)
            {
                JOptionPane.showMessageDialog(this, "Record Adddeddd");
                txtname.setText("");
                txtaddress.setText("");
                txtphone.setText("");
                txtname.requestFocus();  
                Customer();
            }
            
            else
            {
                JOptionPane.showMessageDialog(this, "Record Failed");
            }   
            
        } catch (SQLException ex) {
           ex.printstacktrace();
        }
        
        
    }

Count the No of Customers

         public void Customer()
    {
        try 
        {  
             pst = con.prepareStatement("SELECT COUNT(*) AS customerCount FROM customer");
             ResultSet rs = pst.executeQuery(); 
             while(rs.next())
             {
              int count = rs.getInt("customerCount");
              //  int count = rs.getInt(1);

                txtmsg.setText(String.valueOf(count));
             } 
        }
           catch (SQLException ex) 
          {
            ex.printstacktrace();
           }
    }

i attached the video link. watch this video this help you create System step by step.

 

admin

Recent Posts

Tesla Pi Phone: Is This the Next Super-Phone? Full Review & Details

What Is the Tesla Pi Phone?   Imagine if Tesla, the company that makes famous…

1 week ago

Tailwind CSS Inventory Management POS Project (Free Source Code)

Inventory Management POS systems are now an essential part of modern businesses such as bookshops,…

1 month ago

Build Simple Water System Calculator in Java Using Swing

If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…

5 months ago

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…

5 months 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,…

5 months ago

Best Festivals UK 2025 [Free Guide Included]

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

6 months ago