Java

Movie Ticket Booking System in Java mysql

The Movie Ticket Book Inventory Management System is developed using Java and mysql.java best practice is must if you interested in java. The project is built to manage sales and transactions. To make a new transaction, fields such as: Movie Ticket type, qty,price 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.

In this tutorial, you will learn  jasper reports step by step and designing the java print receipt.java coding practices is very important  for us to grow the knowledge in java day by day. how to be a good programmer in the future. Let go and learn the java mini projects step by step.i have attached the complete project video also how the flow works step by step below.

In order to create the system we have used NetBeans IDE and Mysql database as a backend.

Features

  1. Point of Sales
  2. Stock Management
  3. Java Receipt

Learn how to make this System Step by step

The first step Create the database named with “movieticket“. then established the database connection to download the mysql connector in order to connect Java & mysql.if you don’t  have an idea about  download the mysql connector you can follow this link.

To connect the database please refer the following code. To create the method name connect (); paste the below code inside the Connect () method.

public void Connect()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver"); // Register the mysql driver
            con = DriverManager.getConnection("jdbc:mysql://localhost/

movieticket

","root","");    
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
           ex.printStackTrace();
        }
    }

The system shall be able to select the relevant Movie ticket type.

 

Add the Product details into the JTable

After selected the relevant rice type 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 below table.

Paste this code inside the add button

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{                                         
        int sum = 0;
        int price;
        int qty;
        int tot;
        
        if(chk1.isSelected())
        {
            String odc = chk1.getText();
            price = 300;
            qty = Integer.parseInt(txtodc.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 odc,
                 price,
                 qty,
                 tot
             });
        }
        
        if(chk2.isSelected())
        {
            String Balcony = chk2.getText();
            price = 350;
            qty = Integer.parseInt(txtbalcony.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 Balcony,
                 price,
                 qty,
                 tot
             });  
        }
        
         if(chk3.isSelected())
        {
            String Box = chk3.getText();
            price = 400;
            qty = Integer.parseInt(txtbox.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 Box,
                 price,
                 qty,
                 tot
             });  
        }
        
        if(chk4.isSelected())
        {
            String Superbal = chk4.getText();
            price = 500;
            qty = Integer.parseInt(txtsbalcony.getValue().toString());
             tot = price * qty;
             model = (DefaultTableModel)jTable1.getModel();
             model.addRow(new Object[] 
            {
                 Superbal,
                 price,
                 qty,
                 tot
             });   
        }
        
        for(int i=0; i<jTable1.getRowCount(); i++)
        {
           sum = sum + Integer.parseInt(jTable1.getValueAt(i, 3).toString());
        }
        txtsub.setText(String.valueOf(sum));
    }

Calculating the Total and balance

After that  create the method Sales().we have to create two different tables to store data into the database.we also have to create the following tables from database.
sales tables consist of following colums – id,subtotal,pay,balance.
sales_products tables consist of following colums –id,sales_id,tickettype,qty,price,total

 public void sales() 
    {
        try {      
        String subtotal = txtsub.getText();
        String pay = txtpay.getText();
        String tot = txtbal.getText();
        
        int lastid =0;
        
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost/movieticket","root","");
            String query = "insert into sales(subtotal,pay,balance)values(?,?,?)";
            ps1 = con.prepareStatement(query,Statement.RETURN_GENERATED_KEYS);
            
            ps1.setString(1, subtotal);
            ps1.setString(2, pay);
            ps1.setString(3, tot);
            ps1.executeUpdate();
            
            ResultSet rs = ps1.getGeneratedKeys();
            
            if(rs.next())
            {
                lastid = rs.getInt(1);
            } 
            int rows = jTable1.getRowCount();
            
            String query1 = "insert into sales_product(sales_id,tickettype,qty,price,total)values(?,?,?,?,?)";
            ps2 = con.prepareStatement(query1);
            
            String tickettype = "";
            int price;
            int qty;
            int total = 0;
            
            for(int i=0; i<jTable1.getRowCount(); i++)
            {
                tickettype = (String)jTable1.getValueAt(i, 0);
                price = (int)jTable1.getValueAt(i, 1);
                qty = (int)jTable1.getValueAt(i, 2);
                total = (int)jTable1.getValueAt(i, 3);
                 ps2.setInt(1,lastid);
                 ps2.setString(2,tickettype);
                 ps2.setInt(3,qty);
                 ps2.setInt(4,price);
                 ps2.setInt(5,total);
                 ps2.executeUpdate();
 
            }
            
            JOptionPane.showMessageDialog(this, "Sales Completeeeeee");
            
            
            HashMap a = new HashMap();
            a.put("invo", lastid);
            
            try {
                JasperDesign jdesign = JRXmlLoader.load("C:\\Users\\kobinath\\Documents\\NetBeansProjects\\Movieticket\\src\\movieticket\\report1.jrxml");
                JasperReport jreport = JasperCompileManager.compileReport(jdesign);
                
                JasperPrint jprint = JasperFillManager.fillReport(jreport, a,con);
                
                JasperViewer.viewReport(jprint);
 
            } catch (JRException ex) {
                Logger.getLogger(movieticket.class.getName()).log(Level.SEVERE, null, ex);
            }

        } catch (ClassNotFoundException ex) {
            Logger.getLogger(movieticket.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(movieticket.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

Call the Sales() method inside the Print Invoice button. after calculating the total Print receipt will be released. This print receipt designed by Jsper Reporting.

Paste this code inside the Print Invoice button

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) 
    {                                          
        int sub = Integer.parseInt(txtsub.getText());
        int pay = Integer.parseInt(txtpay.getText());
        int bal = pay - sub;
        txtbal.setText(String.valueOf(bal));
        sales();

    }

 

I have attached the video tutorial below it will help you  to do this  step by step.java projects with source codes will help you to learn java.

 

 

 

 

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…

1 day 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 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…

1 week 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…

1 week ago